forked from fictive-kin/funnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funnel.js
72 lines (61 loc) · 2.03 KB
/
funnel.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var shared = require('./plugin/shared');
var collect = function (sourcesdotdotdot) {
var fetchers = [];
// arguments is not a real array; no forEach
var len = arguments.length;
for (var i=0; i<len; i++) {
fetchers.push(arguments[i]);
}
var fixMetricName = function (name, preserveDot) {
var re = preserveDot ? /[^a-z0-9._-]/ig : /[^a-z0-9_-]/ig;
return name.replace(re, '-').replace(/-+/g, '-').toLowerCase();
};
var asMetricName = function (data, preserveDot) {
var name = ['funnel'];
if (data.explicitMetricName) {
name.push(data.explicitMetricName);
} else {
name.push(data.funnel);
name.push(fixMetricName(data.nodeName));
if (data.serviceName) {
name.push(fixMetricName(data.serviceName));
}
name.push(fixMetricName(data.metricName, preserveDot));
}
return name.join('.');
};
var display = function () {
fetchers.forEach(function (fetcher) {
fetcher(function (data) {
console.log(asMetricName(data, data.preserveMetricNameDot), data.reading);
});
});
};
var toStatsD = function (host, port) {
port = port || 8125;
var SDC = require('statsd-client'),
sdc = new SDC({host: host, port: port, debug: true});
fetchers.forEach(function (fetcher) {
fetcher(function (data) {
sdc.gauge(asMetricName(data, data.preserveMetricNameDot), data.reading)
});
});
};
return {
toStatsD: toStatsD,
display: display
};
};
module.exports = {
collect: collect,
nagios: require('./plugin/nagios'),
mongo: require('./plugin/mongo'),
munin: require('./plugin/munin'),
json: require('./plugin/json'),
cloudwatch: require('./plugin/cloudwatch'),
dbi: require('./plugin/dbi'),
command: require('./plugin/command'),
COUNT: shared.COUNT,
ALL: shared.ALL,
dbiSolo: shared.dbiSolo
}