Utility to get current process metrics.
$ npm install metrics-process
var getMetrics = require( 'metrics-process' );
Gets the current process metrics and invokes a provided callback. The callback should accept two arguments: error
and metrics
.
function onMetrics( error, metrics ) {
if ( error ) {
throw new Error( error );
}
console.log( JSON.stringify( metrics ) );
}
getMetrics( onMetrics );
If no error
is encountered while getting process metrics, error
is null
. The metrics
object is comprised as follows:
{
"pid": 14847,
"uptime": 0,
"mem": {
"rss": 10932.224,
"heapFree": 1934.048,
"heapTotal": 4083.456,
"heapUtilization": 0.5263698200739766,
"memUsed": 13017.088,
"utilization": 0.00151824951171875
},
"cpu": {
"utilization": 0
},
"lag": 0
}
The following metrics are reported...
The process id.
The number of milliseconds the process has been running.
The resident set size, which is the portion of memory held in RAM, as opposed to swap or disk. This metric is reported in kilobytes
.
The amount of memory remaining from which newly created objects will originate. This metric is reported in kilobytes
.
The total amount of memory from which newly created objects can originate. This metric is reported in kilobytes
.
The decimal percentage of utilized heap space.
The amount of memory used by the process. This metric is reported in kilobytes
.
Used memory as a fraction of total system memory.
A decimal percentage describing how much the process utilizes the CPU.
The average number of milliseconds a request has to wait in Node's event queue before being processed. An excess lag means that the process is overloaded. See node-toobusy for more information.
var getMetrics = require( 'metrics-process' );
for ( var i = 0; i < 10; i++ ) {
setTimeout( onTimeout, 1000*i );
}
function onTimeout() {
getMetrics( onMetrics );
}
function onMetrics( error, metrics ) {
if ( error ) {
throw new Error( error );
}
console.log( JSON.stringify( metrics ) );
}
To run an example from the top-level application directory,
$ node ./examples/index.js
Metrics names mirror the conventions set forth in doc-metrix.
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.
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
Copyright © 2014-2015. Athan Reines.