diff --git a/README.md b/README.md index 946d76d..0bcd370 100644 --- a/README.md +++ b/README.md @@ -233,5 +233,20 @@ source = funnel.nagios({ You'll notice that `funnel.ALL` is used here, too. This collects all performance data under this heading. `from` can be an array (or a string for a single server, but you *are* running MongoDB in a replica set, right? (-: ). +### command ### + +This plugin allows you to run arbitrary commands to fetch metrics. + +```javascript +source = funnel.command({ + services: { + 'seconds': function (stdout) { return parseInt(stdout); }, + }, + from: 'date +%s' +}); +``` + + + diff --git a/funnel.js b/funnel.js index 8112e21..927fbc9 100644 --- a/funnel.js +++ b/funnel.js @@ -59,6 +59,7 @@ module.exports = { json: require('./plugin/json'), cloudwatch: require('./plugin/cloudwatch'), dbi: require('./plugin/dbi'), + command: require('./plugin/command'), COUNT: shared.COUNT, ALL: shared.ALL, diff --git a/plugin/command.js b/plugin/command.js new file mode 100644 index 0000000..e718a7e --- /dev/null +++ b/plugin/command.js @@ -0,0 +1,38 @@ +var shared = require('./shared'); + +module.exports = function (service) { + var sys = require('sys') + var exec = require('child_process').exec; + var hostname = require('os').hostname().split('.')[0]; + return function (funneler) { + var from = service.from; + // cast to array + if (typeof from == 'string') { + from = [from]; + } + from.forEach(function (cmd) { + for (var sName in service.services) { + (function (serviceName) { // yum! delicious scope! + exec(cmd, function (error, stdout, stderr) { + if (error) { + console.log("Error.") + console.log("stdout:") + console.log(stdout) + console.log("stderr:") + console.log(stderr) + return false; + } + funneler({ + 'funnel': 'command', + 'nodeName': hostname, + 'serviceName': sName, + 'metricName': cmd, + 'reading': service.services[sName](stdout), + }); + }); + })(sName); + } + }); + } +}; +