OS Metrics
Utility to get system metrics.
Installation
For use in Node.js,
$ npm install metrics-os
Usage
The module exports a single method, which returns an object
containing uptime
, load
, mem
, and cpu
metrics. To use the utility,
var getMetrics =metrics = ;
The following is an example metrics output...
"uptime": 218091000"load":"1m": 1443359375"5m": 158203125"15m": 193359375"mem":"memTotal": 8589934592"memFree": 230801408"ramUtilization": 09731311798095703"cpu":"user": 16288640"nice": 0"system": 7832180"idle": 98866460"irq": 0"user": 7631040"nice": 0"system": 2386640"idle": 112967740"irq": 0"user": 14059800"nice": 0"system": 5183440"idle": 103742200"irq": 0"user": 7632010"nice": 0"system": 2324990"idle": 113028390"irq": 0"userAverage": 114028725"niceAverage": 0"systemAverage": 44318125"idleAverage": 1071511975"irqAverage": 0
Metrics
The following metrics are reported...
uptime
The number of milliseconds since the last system reboot. In contrast to os.uptime()
, the uptime
reported by this utility is in milliseconds
so as to match the units for CPU metrics (idle
, user
, system
, nice
, iqr
).
load.1m
The average number of jobs in the run queue (state R) or waiting for disk I/O (state D) over the past minute.
load.5m
The average number of jobs in the run queue (state R) or waiting for disk I/O (state D) over the past 5 minutes.
load.15m
The average number of jobs in the run queue (state R) or waiting for disk I/O (state D) over the past 15 minutes.
mem.memTotal
The total amount of usable RAM. This metric is reported in kilobytes
.
mem.memFree
The total mount of free RAM. This metric is reported in kilobytes
.
mem.ramUtilization
The decimal percentage of RAM being used.
cpu.user
Number of milliseconds a CPU has spent in user
mode.
cpu.system
Number of milliseconds a CPU has spent in kernel
mode.
cpu.idle
Number of milliseconds a CPU has spent idle.
cpu.nice
Number of milliseconds a CPU has spent in user
mode and had a positive nice
value (executed tasks with low priority).
cpu.iqr
Number of milliseconds spent addressing hardware interrupts.
cpu.<metric>Average
All metrics with the suffix Average
are the mean values calculated across all CPUs.
Examples
var getMetrics = ;for var i = 0; i < 10; i++;{JSON;}
To run an example from the top-level application directory,
$ node ./examples/index.js
Notes
-
As stated in the Node.js documentation,
loadavg
is not supported on Windows platforms. -
Note that the length of the CPU metric
array
is one more than the number of CPUs. -
The metric naming scheme follows 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
Copyright
Copyright © 2014. Athan Reines.