-
-
Save jnbdz/ddac2861c7e85e36fc02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* To enable this backend, include './backends/riemann' in the backends | |
* configuration array: | |
* | |
* Requires Riemann Node client | |
* | |
* backends: ['./backends/riemann'] | |
* | |
*/ | |
var net = require('net'), | |
util = require('util'), | |
http = require('http'); | |
client = require('riemann').createClient({ | |
host: riemannHost, | |
port: riemannPort }); | |
var debug; | |
var flushInterval; | |
var APIKey; | |
var service; | |
var service_name; | |
var time_stamp; | |
var riemannStats = {}; | |
var riemannHost; | |
var riemannPort; | |
var post_stats = function riemann_post_metrics(statString, service_name, time_stamp) { | |
util.log(statString); | |
riemannStats.last_exception = Math.round(new Date().getTime() / 1000); | |
client.send(client.Event({ | |
service: service_name, | |
metric: statsString, | |
time: time_stamp | |
})); | |
}; | |
var flush_stats = function riemann_flush(ts, metrics) { | |
var statString = ''; | |
var numStats = 0; | |
var key; | |
var counters = metrics.counters; | |
var gauges = metrics.gauges; | |
var timers = metrics.timers; | |
var pctThreshold = metrics.pctThreshold; | |
for (key in counters) { | |
var value = counters[key]; | |
var valuePerSecond = value / (flushInterval / 1000); // calculate "per second" rate | |
statsString = value; | |
service_name = key; | |
time_stamp = ts; | |
util.log(statsString) | |
util.log(service_name) | |
post_stats(statString, service_name, time_stamp); | |
} | |
}; | |
var backend_status = function riemann_status(writeCb) { | |
for (stat in riemannStats) { | |
writeCb(null, riemann, stat, riemannStats[stat]); | |
} | |
}; | |
exports.init = function riemann_init(startup_time, config, events) { | |
debug = config.debug; | |
riemannHost = config.riemannHost; | |
riemannPort = config.riemannPort; | |
riemannStats.last_flush = startup_time; | |
riemannStats.last_exception = startup_time; | |
flushInterval = config.flushInterval; | |
events.on('flush', flush_stats); | |
events.on('status', backend_status); | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment