Skip to content
This repository was archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
add command plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
scoates committed Jan 19, 2013
1 parent 6cc5f20 commit 4affb00
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
```





1 change: 1 addition & 0 deletions funnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions plugin/command.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
};

0 comments on commit 4affb00

Please sign in to comment.