node-process-metrics
v0.1.0
Published
retrieve Node.js process metrics
Downloads
1,249
Keywords
Readme
node-process-metrics
Get process, system, memory, CPU, and event loop metrics from a Node.js process. Can be used synchronously, or as an event emitter.
Basic Usage
'use strict';
const NodeProcessMetrics = require('node-process-metrics');
// Use synchronously
const pm = new NodeProcessMetrics();
console.log(pm.metrics());
// Use as an event emitter
const pm = new NodeProcessMetrics({ period: 1000 });
pm.on('metrics', (metrics) => {
console.log(metrics);
});
API
node-process-metrics
exports a single constructor with the following API.
NodeProcessEmitter([options])
- Arguments
options
(object) - An optional configuration supporting the following options:period
(number) - The amount of time that should pass between'metrics'
events being emitted. If not specified,'metrics'
events will not automatically be emitted.loop
(boolean) - Indicates whether event loop delays should be measured. Iffalse
, event loop delays will be reported asNaN
. Defaults totrue
.loopPeriod
(number) - The period used to sample the event loop delay. Defaults to1000
(one second). Ignored ifloop
isfalse
.
'metrics'
Event
The 'metrics'
event contains the following data.
process
(object) - Process level information.system
(object) - System level information containing the following fields, including the system architecture, hostname, load average, platform, amount of free memory, amount of total memory, and system uptime.cpu
(array) - Result ofOs.cpus()
.loop
(number) - The delay associated with each event loop turn, measured in milliseconds.handles
(number) - The number of handles associated with the event loop.requests
(number) - The number of requests associated with the event loop.