Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ npm install microstats
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 }
microstats.on('memory', function(value) { console.log('MEMORY:', value) })
microstats.on('cpu', function(value) { console.log('CPU:', value) })
microstats.on('disk', function(value) { console.log('DISK:', value) })

let options = {}
microstats.start(options, function(err) {
Expand Down
13 changes: 8 additions & 5 deletions optionsparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const util = require('util');
// frequency: '2s'
exports.getFrequency = function(options) {
let f = {};
let g = null;
let regexp = /^(\d+)([smh])$/;

if(!options || !options.frequency) {
f.mode = 'once';
Expand All @@ -20,13 +22,14 @@ exports.getFrequency = function(options) {
f.interval = 2000; // check for alert condition every 2 seconds
return f;
}
else if(options.frequency.length !== 2 || isNaN(options.frequency[0])) {
else if(regexp.test(options.frequency)) {
g = regexp.exec(options.frequency);
} else
throw "Invalid frequency. Try something like 'once', 'onalert', '2m' or '1h'";
}

f.mode = 'time';
let n = parseInt(options.frequency[0]);
let s = options.frequency[1];
let n = parseInt(g[1]);
let s = g[2];

switch(s) {
case 's': f.interval = n * 1000; break;
Expand Down Expand Up @@ -91,4 +94,4 @@ exports.getDiskUsedAlertThreshold = function(diskoptions) {
}

return parseInt(u.split('>')[1].split('%')[0]);
}
}