Provide system statistics in a easy to use API. Made to be cross platform so you can collect statistics on Windows too!
npm install sysstats
var stats = require('sysstats')();
stats.cpus();
// Returns the cpu usages and speeds for the last second.
// [
// {
// speed: "2400",
// times: {
// user: 125,
// nice: 0,
// idle: 875,
// irq: 0,
// system: 0
// }
// }
// ]
stats.mem();
// Returns used and total memory in bytes (handy for getting percentage)
// Output:
// {
// used: 7773933568,
// total: 8529788928
// }
// Close the stats listener
stats.unref();
Creates the stats listener. If it has already been called it will return the previous one.
Options: - interval: The interval between cpu calculations in milliseconds. (default: 1000)
Providing a custom interval will calculate the cpu usage over the past x milliseconds.
Returns the cpu usage as of maximum interval
milliseconds ago. Returns an array with objects containing:
- speed: The speed of each core at last calculation
- times: The amount of time the cpu was in each of the states (See node docs for os.cpus())
The returned data can be maximum interval
seconds old.
Returns the model name for each core (As this is not provided in the cpus call). The keys correspond to the cores in the .cpus call.
Returns the current memory usage as an object containing:
- used: The used memory
- total: The total memory in the system
Unreferences the timer used to calculate the cpu usage. (for automatic closing of node)
Copyright 2015 Jamy Timmermans and Contributors.
Licensed under GPLv2. See LICENSE
for more details.