Monitor
Connect middleware to monitor an application process.
Installation
$ npm install connect-middleware-monitor
Usage
To use the module,
var createMonitor = ;
createMonitor( [...plugin] )
The middleware generator accepts monitor plugins which append to a common metrics object
.
var // Plugin which reports system metrics:sPlugin =// Plugin which reports current process metrics:pPlugin = ;// Create the monitor middleware:var monitor = ;
Note: plugins are executed in the same order as they are provided to the middleware generator.
Each plugin should be a single method which accepts two input arguments: [object
, clbk
]. The object
is a shared object
among all plugins; hence, when choosing plugins, ensure that they are properly namespaced when appending to the object
.
The callback should be invoked once the plugin finishes appending metrics. The callback takes an optional error
argument. Any errors are bubbled up through the middleware.
See monitor-plugin-os and monitor-plugin-process for plugin examples.
monitor( request, response, next )
The generated middleware follows the connect middleware pattern. Monitor metrics are appended to the request
object via a locals
property. Hence, downstream middleware consumers may access the metrics via
var metrics = requestlocalsmonitor;
See the examples below.
Examples
var express =request =sPlugin =pPlugin =createMonitor = ;// Define a port:var PORT = 7331;// Create a new monitor:var monitor = ;// Create a new application:var app = ;// Bind a route using the monitor middleware:app;// Spin up a new server:var server = app;{;}{if errorthrow error ;console;}{responsestatus 200;}
To run an example from the top-level application directory,
$ node ./examples/index.js
Plugins
List of monitor plugins:
- monitor-plugin-os: system-level metrics
- monitor-plugin-process: current process metrics
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2014. Athan Reines.