Giter Club home page Giter Club logo

node-monitor's Introduction

node-monitor

=====

This is an EC2 monitoring application which uses Node.js and the Amazon CloudWatch API. The application is primarly used to push custom metrics, via plugins, to CLoudWatch -- where we can create alarms for failed services, high memory usage, etc. Older branches pushed data to a NoSQL store + websockets (logs), but these functions are being ported to plugins as well.

Prerequisites

  • Amazon EC2 account

Setup

Clone the repository.

cd ~/
git clone git://github.com/franklovecchio/node-monitor.git

Copy the script out of the the directory into a usable location.

cp ~/node-monitor/bin/node-monitor.sh ~/node-monitor.sh
chmod a+x ~/node-monitor.sh

To install all the necessary packages (including node.js and npm):

sudo ~/node-monitor.sh install-debian # Debian
sudo ~/node.monitor.sh install-centos # CentOS

Configure AWS credentials/CloudWatch namespace in config/monitor_config:

cloudwatch_namespace=<Namespace Instance Metrics>
AWS_ACCESS_KEY_ID=<ID>
AWS_SECRET_ACCESS_KEY=<Key>

Start the monitor in production mode:

sudo ~/node-monitor.sh start

To create an Upstart job and be verbose (in Ubuntu):

 touch /var/log/node-monitor.log
 cat >> /etc/init/node-monitor.conf <<EOF
 description "node-monitor"
 start on (local-filesystems and net-device-up IFACE=eth0)
 stop on shutdown
 exec sudo -u root sh -c "cd /home/ubuntu/node-monitor/run && /usr/local/bin/node client.js ec2=true debug=false console=true cloudwatch=true >> /var/log/node-monitor.log 2>&1 &"     
 EOF

Plugins

  • df.sh

To monitor disk size, you need to specify disks in the df_config file:

 /dev/disk0s2
 /dev/sdb
  • filesize.js

To monitor file sizes (like logs), and empty when they hit a maximum, you need to specify files and their max size (in KB) in the filesize_config file:

 /Users/franklovecchio/Documents/my.log=1024
  • free.js

  • health.js

  • lsof.js

  • services.js

To monitor running services, you can specify a service name only for a ps -ef command, or a service name and a port for an lsof command:

cassandra
redis=6379
  • top.js

  • uptime.js

  • who.js

There are 2 types of plugins, poll and step. Plugins are modules which have access to a global set of passed modules, and return asynchronously CloudWatch data. A plugin might look like:

 /* lsof.js */

 /**
  * A plugin for monitoring open files.
  */
 var fs = require('fs');

 var Plugin = {
   name: 'lsof',
   command: 'lsof | wc -l',
   type: 'poll'
 };

 this.name = Plugin.name;
 this.type = Plugin.type;

 Plugin.format = function (data) {
   data = data.replace(/^(\s*)((\S+\s*?)*)(\s*)$/, '$2');
   data = data.replace('%', '');
   return data;
 };

 this.poll = function (constants, utilities, logger, callback) {
   self = this;
   self.constants = constants;
   self.utilities = utilities;
   self.logger = logger;

   var exec = require('child_process').exec, child;
   child = exec(Plugin.command, function (error, stdout, stderr) {
     callback(Plugin.name, 'OpenFiles', 'Count', Plugin.format(stdout.toString()), Plugin.format(stdout.toString()));
   });
 };

Coding on the Shoulders of Giants

NodeMonitor

Node-Activity-Monitor-Without-A-Websocket

node-monitor

node-websocket-activity-monitor

keep-a-nodejs-server-up-with-forever

taking-baby-steps-with-node-js-some-node-js-goodies

1420-node-js-calculating-total-filesize-of-3-files

get-program-execution-time-in-the-shell

nodejs-too-many-open-files.html

node-js-return-result-of-file

things-i-learned-from-my-node.js-experiment

long-polling-example-with-nodejs

log-collection-server-with-node-js

experimenting-with-node-js

nodejs-events-and-recursion-readdir

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.