microstats
Version:
A node module that monitors Memory, CPU and Disk utilization and alerts the caller through events, either periodically or when a user defined threshold is breached. Currently available for linux, macOS and windows.
12 lines (10 loc) • 435 B
JavaScript
;
const os = require('os');
module.exports = function(statEmitter, options) {
let total = parseInt(os.totalmem());
let free = parseInt(os.freemem());
let usedpct = Number(parseFloat(((total - free) / total * 100)).toFixed(2));
if(!options.threshold || options.threshold === 0 || usedpct > options.threshold) {
statEmitter.emit('memory', { usedpct: usedpct, total: total, free: free });
}
}