Code Monkey home page Code Monkey logo

node-monitor's Introduction

Monitor your Node.js application

Build Status

Introduction

Node-monitor is a library for remote monitoring and control of your Node.js app servers.

Like JMX in the Java world, node-monitor comes with a handful of general monitors, and allows you to create custom monitors for your application.

These monitors can be scripted using JavaScript, or placed onto a dashboard.

Project Guidelines

  • Simple - Get started quickly
  • Powerful - For multi-node enterprise deployment
  • Lightweight - Inactive until used, small footprint during use
  • Flexible - Easy to write custom monitors for your app
  • Stable - Well tested foundation for module developers

Getting Started

Run the following from your app server directory

$ npm install monitor

Then place the following line in your application bootstrap, and restart your server

require('monitor').start();

Monitoring your app with a REPL console

Ad-hoc monitoring can be done from a REPL console.

Start up the REPL, and get the Monitor class. Feel free to copy/paste these lines into your console:

$ node
> var Monitor = require('monitor');
undefined

Now connect a monitor to a probe on your app server. There are a handful of built-in probes, and you can build custom probes for your application or npm module.

For this example, we'll monitor the Process probe:

> var processMonitor = new Monitor({probeClass:'Process'});
> processMonitor.connect();

The monitor is a Backbone.js data model so it updates in real time, and you can get all fields with toJSON():

> processMonitor.get('freemem');
86368256
> processMonitor.get('freemem');
80044032
> processMonitor.toJSON();
...

As the monitor changes, it emits change events:

> processMonitor.on('change', function() {
... console.log(processMonitor.get('freemem'));
... });

Monitoring your app with a custom script

Using Node.js as a scripting language, you can write custom monitors that do anything Node.js can do. Here's an example that prints to the console when free memory falls below a threshold.

Save this file to low-memory-warn.js, and run node low-memory-warn

// Low memory warning monitor
var Monitor = require('monitor');
var LOW_MEMORY_THRESHOLD = 100000000;

// Set the probe to push changes every 10 seconds
var options = {
  hostName: 'localhost',
  probeClass: 'Process',
  initParams: {
    pollInterval: 10000
  }
}
var processMonitor = new Monitor(options);

// Attach the change listener
processMonitor.on('change', function() {
  var freemem = processMonitor.get('freemem');
  if (freemem < LOW_MEMORY_THRESHOLD) {
    console.log('Low memory warning: ' + freemem);
  }
});

// Now connect the monitor
processMonitor.connect(function(error) {
  if (error) {
    console.error('Error connecting with the process probe: ', error);
    process.exit(1);
  }
});

Monitoring your app in a browser

The above script runs just as well within an html <script> tag as on the server. For example, change the var Monitor = require('monitor'); line to something like this:

<script src="/path/to/monitor/dist/monitor-all.min.js"></script>

The browser distribution included in node-monitor exports a single variable Monitor to the global namespace, and it can be used just like the Monitor variable in var Monitor = require('monitor').

Your browser will probably have to be pointing to localhost or behind your firewall in order to connect with the app server on the configured monitor port. See Security Concerns below.

Monitoring your app in a dashboard

Monitor-Dashboard

The monitor-dashboard application lets you visualize your monitors in a dashboard.

$ npm install monitor-dashboard
$ npm start monitor-dashboard

Security Concerns

Exposing the internals of your app server is a high security risk. By default, the server listens on port 42000 and will connect with localhost clients only.

In order to monitor across machines, the default configuration must be changed to listen beyond localhost. Before doing this, it is recommended to understand the risks and have external measures in place to prevent unauthorized access.

See notes in the config/external.js file for more information.

Links

License

May be freely distributed under the MIT license
See the LICENSE file.
Copyright (c) 2010-2014 Loren West

node-monitor's People

Contributors

lorenwest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-monitor's Issues

npm package.json strings are not quoted

It appears that node 0.4.0 and node 0.5.0-pre are more particular in the JSON they will allow. Attempting to npm install monitor with those versions yields this:

Ryans-17-MBP-2:node wrb$ npm install monitor
npm ERR! couldn't read package.json in /var/folders/zH/zHPL9C4QGLyyHkzBTjnp1k+++TI/-Tmp-/npm-1298045898236/1298045898236-0.22087552351877093/contents/package
npm ERR! Error installing [email protected]
npm ERR! Error: Failed to parse json
npm ERR! Unexpected token ILLEGAL
npm ERR! {
npm ERR! name: "monitor",
npm ERR! version: "0.2.9",
npm ERR! main: "./lib/node-monitor.js",
npm ERR! description: "Runtime monitoring for node.js applications",
npm ERR! author: "Loren [email protected]",
npm ERR! directories: {lib: "./lib", test: "./test"},
npm ERR! modules: {
npm ERR! "console-logger": "./logger/console-logger",
npm ERR! "file-logger": "./logger/file-logger",
npm ERR! "log4js-logger": "./logger/log4js-logger",
npm ERR! "os-cmd-logger": "./logger/os-cmd-logger",
npm ERR! "email-logger": "./logger/email-logger",
npm ERR! "couchdb-logger": "./logger/couchdb-logger"
npm ERR! },
npm ERR! dependencies: {
npm ERR! "config": ">=0.2.8",
npm ERR! "sprintf": ">=0.1.1",
npm ERR! "vows": ">=0.5.6",
npm ERR! "log4js": ">=0.2.3",
npm ERR! "couch-client": ">=0.0.3"
npm ERR! },
npm ERR! engines: {"node": ">=0.2.4"},
npm ERR! scripts: {
npm ERR! test: "vows test/.js --spec"
npm ERR! }
npm ERR! }
npm ERR!
npm ERR! at /usr/local/lib/node/.npm/npm/0.3.0-8/package/lib/utils/read-json.js:73:13
npm ERR! at P (/usr/local/lib/node/.npm/npm/0.3.0-8/package/lib/utils/read-json.js:62:40)
npm ERR! at cb (/usr/local/lib/node/.npm/npm/0.3.0-8/package/lib/utils/graceful-fs.js:31:9)
npm ERR! at [object Object]. (fs.js:86:5)
npm ERR! at [object Object].emit (events.js:39:17)
npm ERR! at afterRead (fs.js:840:12)
npm ERR! Report this entire* log at http://github.com/isaacs/npm/issues
npm ERR! or email it to [email protected]
npm ERR! Just tweeting a tiny part of the error will not be helpful.
npm not ok

If I quote each string in that file, JSON.parse works.

Support for HTTP monitoring?

Hello,

I apologize for asking this question here but I couldn't find another way to ask you this as this really isn't an "issue".

I'm curious, is there a way to do HTTP monitoring on here or would that require me to create my own my own data probe and monitor probe? For example, I would like to connect to a server via HTTP and do things like ping and request various logs (the app/server I would connect to is not a node.js app). From there, I would parse them, display them on screen, throw up warnings and errors, get those values from the logs to populate the gauges, etc.

BTW, love the work you have done. Looks fantastic!

Thanks!

"Add component" needs scrollbar by default.

When I select "Add Component", the objects move around the canvas, instead of being able to view them with a scrollbar. Once the mouse is hovering, a scrollbar activates and the icons shift places.

How can I add additional data to the monitor result?

Hi,

As I know, this module use socket to communicate between a remote server and a server to be measured, and I can get data from this command processMonitor.toJSON();. How can I utilize the socket connection or the JSON file format to add my data? For example, I can add a list of files in a specified folder to the JASON file before sending to the remote server.

Thank you in advance.

npm start monitor failed

I run the npm start monitor
but failed.

and do you have any sample/example to use the dashboard?

thank you.

process.EventEmitter is deprecated in Node.js v6.*.*

process.EventEmitter is deprecated in Node.js v6..

It is causing a deprecated warning when loading node-monitor,

DeprecationWarning: process.EventEmitter is deprecated. Use require('events') instead.

Tested on Node.js v6.1.0, on Windows.

Cannot get output when running a nodejs script file

Hi,

Thank for providing an interesting measurement tool in NodeJS.
I had a problem when running your tool. Your example worked great in the Ubuntu terminal but when It came to a script file. It did not print out an output as it did in the terminal (the same error with nodejs app.js and node app.js) (As shown in the attached).

capture

Monitor an application from Browser

Hi lorenwest, I have N client applications that I need to monitor, all of them in different machines and one application as monitor server. When I try to monitor a client application from the browser using dist library I can't do a connection, I've inserted the script:

<script src="path/to/monitor/dist/monitor-all.js"></script>

var monitoProcess = new Monitor({
        probeClass: 'Process',
        hostName: ' IPClientApplication '
    });

monitoProcess.connect(function(error) {
        if (error) {
            console.log('Error connecting with the process probe: ', error);
        }
    });
 monitoProcess.on('connect', function(){
        console.log("Connected!");
    });
    monitoProcess.on('change', function()
    {
        var freemem = monitoProcess.get('freemem');
        console.log("Free memory: %d", freemem);
    });

But I don't get the connection to ProbeClass:'Process', however, if I do the same connection but from server side, I get that connection. What can I be doing wrong? By the way, I have in my client applications the property "allowExternalConnections" to true. Do you have an example how to use dashboard components individually in a browser?

Thanks!

Troubles running example scripts on Mac

This may be a replay issue from when I was exploring the dashboard here (I appoligize in advance if this is a repeat!):
lorenwest/monitor-dashboard#4

Running Mac OS X 10.9.1, I cd to my clean project directory and install node-monitor:

sudo npm install monitor

A new 'node_modules' folder appears with a 'monitor' folder and files there, cool!

keeping Terminal open, I attempt this:

$ node
> var Monitor = require('monitor');
undefined

It returns 'undefined'. Now, if I run this instead:

var Monitor = require('./node_modules/monitor/monitor.js');

I get this:

> Monitor service started on host: localhost

External connections disabled.
See /Users/owntheweb/Documents/personal/statMonitor/server/gatherer/config/external.js for more information.

Cool! So moving on to the example low memory alert in low-memory-warn.js, if I run the example as-is, it runs without error and exits immediately, not printing anything in Terminal. If I alter it to match the above require line, errors occur.

Here's the altered low-memory-warn.js script:

// Low memory warning monitor
//var Monitor = require('monitor'); //THIS PRODUCES NOTHING, APP RUNS WITHOUT ERROR, EXITS IMMEDIATELY
var Monitor = require('./node_modules/monitor/monitor.js'); //THIS RESULTS IN ERRORS
var LOW_MEMORY_THRESHOLD = 100000000;

// Set the probe to push changes every 10 seconds
var options = {
  hostName: 'localhost',
  probeClass: 'Process',
  initParams: {
    pollInterval: 10000
  }
}
var processMonitor = new Monitor(options);

// Attach the change listener
processMonitor.on('change', function() {
  var freemem = processMonitor.get('freemem');
  if (freemem < LOW_MEMORY_THRESHOLD) {
    console.log('Low memory warning: ' + freemem);
  }
});

// Now connect the monitor
processMonitor.connect(function(error) {
  if (error) {
    console.error('Error connecting with the process probe: ', error);
    process.exit(1);
  }
});

Here's the result:

                        __________
_______ ___________________(_)_  /______________ 
__  __ `__ \  __ \_  __ \_  /_  __/  __ \_  ___/
_  / / / / / /_/ /  / / /  / / /_ / /_/ /  /
/_/ /_/ /_/\____//_/ /_//_/  \__/ \____//_/

[2014-02-20T16:36:17.473Z] [FATAL] monitor.moniotor.uncaught - Uncaught Exception: object is not a function
[2014-02-20T16:36:17.475Z] [FATAL] monitor.moniotor.uncaught - TypeError: object is not a function
    at Object.<anonymous> (/Users/owntheweb/Documents/personal/statMonitor/server/gatherer/low-memory-warn.js:14:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Here's line 14:

var processMonitor = new Monitor(options);

Any thoughts on what I might be doing wrong? I understand that MacOS may be a bit touchy. If I need to move all this to a Linux machine (my final project will be on Linux), let me know.

Thanks for the feedback in advance!

Node-monitor getting a facelift

This is a heads up that the node-monitor library has undergone a major upgrade, and will be arriving within the upcoming weeks.

The compatibility version has been changed to 0.4.x, so if your application uses the current node-monitor package, you will need to change your package.json to disallow automatic upgrades into 0.4.x and above. I recommend changing your dependencies to this:

"monitor": "<0.4.0"

This will allow updates to the existing monitor package up to, but not including the incompatible version.

And keep your eyes open for the announcement of the new node-monitor. Real time application monitoring dashboard for node.js.

deps._.out reference in stdout-logger.js fails on 0.4.2

Apps that use monitor fail to start in 0.4.2 due to stdout-logger.js attempting to reference deps._.out on line 14:

deps._.out("stdout") in stdout

node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object function (obj) { return new wrapper(obj); } has no method 'out'
at Object. (/usr/local/lib/node/.npm/monitor/0.2.11/package/logger/stdout-logger.js:14:8)
at Module._compile (module.js:383:26)
at Object..js (module.js:389:10)
at Module.load (module.js:315:31)
at Function._load (module.js:276:12)
at require (module.js:327:19)
at Object. (/usr/local/lib/node/.npm/monitor/0.2.11/package/deps.js:29:18)
at Module._compile (module.js:383:26)
at Object..js (module.js:389:10)
at Module.load (module.js:315:31)

error running monitor

trying to run monitor on my machine before install this project via npm gave me a complaint about java. Then I did

 git:(master) which monitor
/Users/harrymoreno/programming/android/adt-bundle/sdk/tools/monitor

so another application named monitor exists. What's the best way to try out node-monitor ?

Test with a remote Server

Hi, i'm new with this library, In the test folder and documentation I see how connect with a remote server so...
I have in my comp1 (as server to monitor)
(192.168.1.70)

var Monitor = require('monitor');

var serverMon = new Monitor.Server();
serverMon.start();

serverMon.on('start', function() {
console.log("Server Started...");
});

And my output is "Server Started..." Ok

In my comp2 (control computer) I have my monitorApp

(192.168.1.80)
var processMonitor = new Monitor({
probeClass: 'Process',
hostName: '192.168.1.70'
});
processMonitor.connect(function(error) {
if(error) console.log("Error " + error);

console.log("Connected...");

});

And I don't get a connection with my server... I'm doing something wrong? or I don't understand the function of the Classes? My test was even with hostName:'192.168.1.70:42000' with default port. If there is a complete example of monitoring a remote server will be very helpful.

Thanks so much...

node-monitor crashes

When I add this line:

require('monitor').start();

It gives me this stack error

monitor/node_modules/config/lib/config.js:1410
global.NODE_CONFIG.watchForConfigFileChanges();
                   ^
TypeError: Object [object Object] has no method 'watchForConfigFileChanges'
    at Object.<anonymous>        (/Users/andy/Development/javascript/rovio/node_modules/monitor/node_modules/config/lib/config.js:1410:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /Users/andy/Development/javascript/rovio/node_modules/monitor/lib/Monitor.js:743:22
    at Object.<anonymous>     (/Users/andy/Development/javascript/rovio/node_modules/monitor/lib/Monitor.js:778:2)
    at Module._compile (module.js:456:26)

Removing components

I cannot remove components in the 'component settings' menu, and when editing components

log4js test failing - and fix

In
7-log4js-logger-test.js

change
var log4js = deps.log4js;

to
var log4js = deps.log4js();

This matches the log4js docs.

Build error on install

I get this build error on npm install monitor:

make: Entering directory '/home/user/test/app/node_modules/monitor/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
bufferutil.target.mk:96: recipe for target 'Release/obj.target/bufferutil/src/bufferutil.o' failed

getConnection() return null

I tried to run the example from here. (http://lorenwest.github.io/node-monitor/doc/classes/Monitor.html)

Though I received data from Server periodically, the function processMonitor.getConnection() return null.
Also, the function processMonitor.control('ping', function(error, response), return null due to the error [ERROR] Monitor.control.Process.ping - Probe not connected

server.js
`var Monitor = require('monitor');

var options = {
probeClass: 'Process',
initParams: {
pollInterval: 10000
}
}
var Probe = new Monitor.Probe(options);
Probe.onControl('ping', function(error, response) {
response = 'asdasdasd';//console.log('Ping response: ', response);
});

var server = new Monitor.Server();
server.start();`

client.js
`var options = {
hostName: '192.168.2.3',
probeClass: 'Process',
initParams: {
pollInterval: 10000
}
}
var Monitor = require('monitor');
// Connecting a monitor to a probe
var processMonitor = new Monitor(options);
processMonitor.connect(function(err) {console.log('aa', err);});

//var Connection = Monitor.Connection(options);

// Monitoring the probe
processMonitor.on('change', function(){
console.log('Changes:', processMonitor.get('freemem'));
});

// Remote control
processMonitor.control('ping', function(error, response) {
console.log('Ping response: ', response);
});

console.log('getConnection()', processMonitor.getConnection());`

Need more examples

I want to monitor log, but I have no idea how to do after reading the docs.

Error watching for file (runtime.json) ENOSPC

Hey guys,

Just installed the package and I got some weird error when I start my application.

I've isolated the faulty line to this (I don't even do anything with it):

var Monitor = require('monitor');

The error being :

Error watching for file: /home/fcharette/Documents/workspace/gap-telemetry/config/runtime.json { [Error: watch ENOSPC] code: 'ENOSPC', errno: 'ENOSPC', syscall: 'watch' }

monitor version from npm, v0.6.10

I run iojs v1.8.2, npm 2.9.0
I'm on Ubuntu 15
I have plenty of space on my disk (and on /tmp)

Any ideas ?
Thank you!

Please add at least one example

Hi,

I would really like to use node-monitor module, however I can't get it to connect to my process.
I've included require("monitor-min").start() in my project, and I would like to start the node-monitor on the same server to add some charts and monitor it.
To be honest... I have got no clue on how to add a chart to monitor for example memory usage.
A single example would be awesome!

Thanks

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.