npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monitor

v0.6.10

Published

Runtime monitoring for node.js applications

Downloads

1,000

Readme

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