microstats

0.1.2 • Public • Published

microstats

NPM Version Linux Build

microstats is a node utility that can be used to monitor OS events such as CPU utilization, memory and disk consumption. It can be used to 'alert' the user when user defined thresholds are breached. Currently available for linux, macos and windows.

Install

npm install microstats

Usage

const microstats = require('microstats')
 
// Event emits
microstats.on('memory', function(value) { console.log('MEMORY:', memory }
microstats.on('cpu', function(value) { console.log('CPU:', memory }
microstats.on('disk', function(value) { console.log('DISK:', memory }
 
let options = {}
microstats.start(options, function(err) {
  if(err) console.log(err);
})
 
...
...
microstats.stop();

options

3 modes of operation -

  • 'once': Will check all stats, report current numbers and stop.
let options = { frequency: 'once' }
  • 'timer': Will check all stats periodically on a user defined timer and report each check.
let options = { frequency: '5s' }

Values for frequency could be something like

'5s' // 5 seconds
'5m' // 5 minutes
'5h' // 5 hours
  • 'onalert': Will check all stats periodically, but report only when the numbers exceed user defined threshold.
options = {
  frequency: 'onalert'
  memoryalert: { used: '>60%' }
  cpualert: { load: '>80%' }
  diskalert: { used: '>70%' }
}

If 'onalert' is used without specifying the thresholds, a default threshold value of 50% will be used for all stats.

diskalert

diskalert options can be customized to specify the disks / mounts to be monitored. If no 'filesystem(s)' or 'mount(s)' are specified, all the available disks will be considered.

  • linux/macos example(s)
options = {
  frequency: 'once'
  diskalert: { 
    used: '>70%',
    mount: '/'
  }
}
 
options = {
  frequency: 'once'
  diskalert: { 
    used: '>70%',
    mounts: ['/home', /dev']
  }
}
  • windows example(s)
options = {
  frequency: 'once'
  diskalert: { 
    used: '>70%',
    filesystem: 'C:'
  }
}
 
options = {
  frequency: 'once'
  diskalert: { 
    used: '>70%',
    filesystems: ['C:','D:']
  }
}

Sample output

MEMORY: { usedpct: 55.33, total: 34359738368, free: 15349305344 }
DISK: { filesystem: '/dev/disk0s2',
  mount: '/',
  usedpct: 40.64,
  total: 976265452,
  free: 579478940 }
DISK: { filesystem: '/dev/disk1s2',
  mount: '/Volumes/MyPhotos',
  usedpct: 88.05,
  total: 246865880,
  free: 29491752 }
CPU: { loadpct: 39.28, userpct: 10.71, syspct: 28.57, idlepct: 60.71 }

License

MIT

Package Sidebar

Install

npm i microstats

Weekly Downloads

85

Version

0.1.2

License

MIT

Last publish

Collaborators

  • sv-code