-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatsd_backend.js
51 lines (42 loc) · 1.13 KB
/
statsd_backend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* vim: et:sw=2:ts=2
*
* A statsd backend for alertd
*
* To enable this backend, include 'alert' in the backends
* configuration array:
*
* backends: ['alert']
*
* This backend supports the following config options:
*
* alertConfig: Path to alertd config file.
*
*/
var alerts = require('./alerts')
, config = require('./config')
, util = require('util')
var flush_stats = function alert_flush(ts, stats) {
var key;
for (key in stats.counters) {
alerts.check(key, stats.counters[key]);
}
for (key in stats.gauges) {
alerts.check(key, stats.gauges[key]);
}
};
var backend_status = function alert_status(writeCb) {
alerts.monitors().forEach(function(monitor) {
writeCb(null, 'alert', monitor.name, monitor.state);
for (var k in monitor.stats) {
writeCb(null, 'alert', monitor.name + '.' + k, monitor.stats[k]);
}
});
};
exports.init = function alert_init(startup_time, statsd_config, events) {
config.configFile(statsd_config.alertConfig, function(config) {
alerts.configure(config);
});
events.on('flush', flush_stats);
events.on('status', backend_status);
return true;
};