Skip to content

Commit

Permalink
support optional hostname + cluster in metric name
Browse files Browse the repository at this point in the history
  • Loading branch information
fetep committed Feb 16, 2011
1 parent 890bdab commit 1ee5bf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions exampleConfig.js
Expand Up @@ -2,5 +2,7 @@
graphitePort: 2003
, graphiteHost: "graphite.host.com"
, port: 8125
, hostname: "www1"
, cluster: "foo"
}

26 changes: 16 additions & 10 deletions stats.js
Expand Up @@ -7,6 +7,15 @@ var counters = {};
var timers = {};
var debugInt, flushInt, server;

function makeStat(config, name, value, ts) {
var stat = name;
if (config.hostname && config.cluster) {
stat += "." + config.cluster + "." + config.hostname;
}
stat += " " + name + " " + value + " " + ts + "\n";
return stat;
}

config.configFile(process.argv[2], function (config, oldConfig) {
if (! config.debug && debugInt) {
clearInterval(debugInt);
Expand Down Expand Up @@ -65,8 +74,7 @@ config.configFile(process.argv[2], function (config, oldConfig) {

for (key in counters) {
var value = counters[key] / (flushInterval / 1000);
var message = 'stats.' + key + ' ' + value + ' ' + ts + "\n";
statString += message;
statString += makeStat(config, 'stats.' + key, value, ts);
counters[key] = 0;

numStats += 1;
Expand Down Expand Up @@ -100,19 +108,17 @@ config.configFile(process.argv[2], function (config, oldConfig) {

timers[key] = [];

var message = "";
message += 'stats.timers.' + key + '.mean ' + mean + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.upper ' + max + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.upper_' + pctThreshold + ' ' + maxAtThreshold + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.lower ' + min + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.count ' + count + ' ' + ts + "\n";
statString += message;
statString += makeStat(config, 'stats.timers.' + key + '.mean', mean, ts);
statString += makeStat(config, 'stats.timers.' + key + '.upper', upper, ts);
statString += makeStat(config, 'stats.timers.' + key + '.upper_' + pctThreshold, maxAtThreshold, ts);
statString += makeStat(config, 'stats.timers.' + key + '.lower', lower, ts);
statString += makeStat(config, 'stats.timers.' + key + '.count', count, ts);

numStats += 1;
}
}

statString += 'statsd.numStats ' + numStats + ' ' + ts + "\n";
statString += makeStat(config, 'statsd.numStats', numStats, ts);

var graphite = net.createConnection(config.graphitePort, config.graphiteHost);

Expand Down

0 comments on commit 1ee5bf9

Please sign in to comment.