cpu-stats

Calculates per-core CPU usage of the current computer


Keywords
cpu, usage, utilisation, utilization, monitor, system
License
ISC
Install
npm install cpu-stats@1.0.0

Documentation

cpu-stats

Dependency Status devDependency Status Build Status Coverage Status

Calls a callback with the current CPU utilisation status in percent per core.

var cpuStats = require('cpu-stats')

// the first argument is how long to sample for in ms.
// longer is more accurate but, you know, longer.
// if omitted, defaults to one second.
cpuStats(1000, function(error, result) {
  if(error) return console.error('Oh noes!', error) // actually this will never happen

  console.info(result)
})

Will output:

[
  { cpu: 14, user: 7, nice: 0, sys: 7, idle: 86, irq: 0 },
  { cpu: 3, user: 1, nice: 0, sys: 2, idle: 97, irq: 0 },
  { cpu: 9, user: 5, nice: 0, sys: 4, idle: 91, irq: 0 },
  { cpu: 2, user: 1, nice: 0, sys: 1, idle: 98, irq: 0 }
]

All numbers are in % and will probably not be integers.

cpu is a convenience addition of all activity per core minus idle time.