metrics-process

1.0.2 • Public • Published

Process Metrics

NPM version Build Status Coverage Status Dependencies

Utility to get current process metrics.

Installation

$ npm install metrics-process

Usage

var getMetrics = require( 'metrics-process' );

getMetrics( clbk )

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
}

Metrics

The following metrics are reported...

pid

The process id.

uptime

The number of milliseconds the process has been running.

mem.rss

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.

mem.heapFree

The amount of memory remaining from which newly created objects will originate. This metric is reported in kilobytes.

mem.heapTotal

The total amount of memory from which newly created objects can originate. This metric is reported in kilobytes.

mem.heapUtilization

The decimal percentage of utilized heap space.

mem.memUsed

The amount of memory used by the process. This metric is reported in kilobytes.

mem.utilization

Used memory as a fraction of total system memory.

cpu.utilization

A decimal percentage describing how much the process utilizes the CPU.

lag

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.

Examples

var getMetrics = require( 'metrics-process' );
 
for ( var i = 0; i < 10; i++ ) {
    setTimeout( onTimeout, 1000*);
}
 
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

Notes

Metrics names mirror the conventions set forth in doc-metrix.

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

MIT license.

Copyright

Copyright © 2014-2015. Athan Reines.

Package Sidebar

Install

npm i metrics-process

Weekly Downloads

2

Version

1.0.2

License

none

Last publish

Collaborators

  • kgryte