}, function(err, conf) { /***************************** * * Expose metrics, measure anything * http://docs.keymetrics.io/docs/usage/pmx-keymetrics-library/#expose-metrics-measure-anything * ****************************/ var Probe = pmx.probe(); var value_to_inspect = 0; /** * .metric, .counter, .meter, .histogram are also available (cf doc) */ var val = Probe.metric({ name : 'test-probe', value : function() { return value_to_inspect; }, /** * This allow to trigger an issue when a value is reached * threshold, thresold-avg, smart-1 are others methods allowed * http://docs.keymetrics.io/docs/usage/pmx-keymetrics-library/#alert-system-for-custom-metrics */ alert : { mode : 'threshold', value : 20, msg : 'test-probe alert!', action : function(val) { // Here we can optionally call a custom function to do something console.log('exiting because val reached %d', val); //process.exit(1); } } }); setInterval(function() { value_to_inspect++; }, 200); var value_to_inspect2 = 0; var valverine = Probe.metric({ name : 'toto', value : function() { return value_to_inspect2; } /** * This allow to trigger an issue when a value is reached * threshold, thresold-avg, smart-1 are others methods allowed * http://docs.keymetrics.io/docs/usage/pmx-keymetrics-library/#alert-system-for-custom-metrics */ }); setInterval(function() { value_to_inspect2++; }, 20); /**************************** * * Simple remote function (returns instant values) * ***************************/ pmx.action('env', function(reply) { return reply({ env: process.env }); }); /**************************** * * Long running remote function (with log storage) * ***************************/ var spawn = require('child_process').spawn; pmx.scopedAction('lsof cmd', function(options, res) { var child = spawn('lsof', []); child.stdout.on('data', function(chunk) { chunk.toString().split('\n').forEach(function(line) { /** * Here we send logs attached to this command */ res.send(line); }); }); child.stdout.on('end', function(chunk) { /** * Then we emit end to finalize the function */ res.end('end'); }); }); });
issues : true, meta : true } // Status // Green / Yellow / Red } }); pmx.scopedAction('testo', function(data, emitter) { var i = setInterval(function() { emitter.send('datard'); }, 100); setTimeout(function() { emitter.end('end'); clearInterval(i); }, 3000); }); var spawn = require('child_process').spawn; pmx.scopedAction('long running lsof', function(data, res) { var child = spawn('lsof', []); child.stdout.on('data', function(chunk) { chunk.toString().split('\n').forEach(function(line) { res.send(line); });