1.3.0 • Published 7 years ago
cpu-memory-monitor v1.3.0
cpu-memory-monitor
CPU & Memory Monitor, auto dump.
Install
$ npm i cpu-memory-monitor --saveUsage
require('cpu-memory-monitor')(options)example:
require('cpu-memory-monitor')({
cpu: {
interval: 1000,
duration: 30000,
threshold: 60,
profileDir: '/tmp',
counter: 3,
limiter: [5, 'hour']
},
memory: {
interval: 5000,
threshold: '500mb',
...
}
})will generate:
cpu-${process.pid}-${Date.now()}.cpuprofile
memory-${process.pid}-${Date.now()}.heapsnapshot
leak-memory-${process.pid}-${Date.now()}.heapsnapshotrequire('cpu-memory-monitor')({
cpu: {
interval: 1000,
duration: 30000,
threshold: 60,
profileDir: '/tmp',
counter: 3,
limiter: [5, 'hour']
}
})means: every 1000ms check CPU usage, when CPU(%) > 60% for 3 times, then dump 30000ms CPU usage(.cpuprofile) to /tmp, dump could be triggered at most 5 times an hour.
you can also use:
$ kill -USR2 PIDsee heapdump.
Options
- cpu
{Object}- interval
{Number}: interval(ms) for check CPU usage, default:1000 - duration
{Number}: duration(ms) for profiling CPU, default:30000 - threshold
{Number}:process max CPU(%) usage, default:90 - profileDir
{String}: directory for save cpuprofile, default:process.cwd() - counter
{Number}:the number of CPU > threshold, then dump, default:1 - limiter
{Array}: options pass to limiter, default:[3, 'hour']
- interval
- memory
{Object}- interval
{Number}: interval(ms) for check Memory usage, default:1000 - threshold
{String}:process max Memory usage, default:1.2gb, see bytes - profileDir
{String}: directory for save heapsnapshot, default:process.cwd() - counter
{Number}:the number of Memory > threshold, then dump, default:1 - limiter
{Array}: options pass to limiter, default:[3, 'hour']
- interval
NB: If omit cpu/memory option, cpu-momery-monitor will not monitor it.
License
MIT