Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including micro-monitor with all npm packages installed. Try it out:

var microMonitor = require("micro-monitor")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

micro-monitor v3.1.0

add a monitoring endpoint to your node background services

Micro Monitor

Build Status Coverage Status

Add a standardized monitoring endpoint to your application. Especially useful for adding monitoring to services that do not expose an HTTP interface.

Basic Usage

Simply initialize the monitor when your application starts up:

const Monitor = require('micro-monitor')

let monitor = Monitor(9999, () => {
// do something now that monitoring is running
})
  • http://0.0.0.1:9999/_monitor/status is now available, and will respond with a 200 status and status object:
{
  "pid": 42176,
  "uptime": 0.796,
  "rss": {
    "rss": 53907456,
    "heapTotal": 37728256,
    "heapUsed": 26032248
  },
  "cmdline": [
    "/Users/benjamincoe/.nvm/versions/node/v7.1.0/bin/node",
    "/Users/benjamincoe/npm-inc/micro-monitor/node_modules/mocha/bin/_mocha",
    "test.js"
  ],
  "git": "b0c57aa"
}
  • http://0.0.0.1:9999/_monitor/ping is also available and will respond with status 200 and the text pong.

Customizing Status Information

You can customize the status information returned using contribute:

  • monitor.contribute(contributor): contribute additional information to the status object returned on /_monitor/status.
    • contributor: a function returning the object to supplement the status object with.

Configuration

When the monitor is first started, it will attempt to pull the commit hash for the current project by performing a git rev-parse. If you wish to supply your own value for the git field, set the BUILD_HASH environment variable.

Shutdown

You can halt the monitor using stop:

  • monitor.stop() ⇒ Promise: halt the monitor
    • close: a function returning a Promise which is resolved once the monitor server has halted.

License

ISC

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free