This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

add command plugin

  • Loading branch information...
scoates committed Jan 19, 2013
1 parent 6cc5f20 commit 4affb00df47756c572b7cf5ef0bc2139329debdb
Showing with 54 additions and 0 deletions.
  1. +15 −0 README.md
  2. +1 −0 funnel.js
  3. +38 −0 plugin/command.js
View
@@ -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'
+});
+```
+
+
+
View
@@ -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,
View
@@ -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.