Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion exampleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ Optional Variables:
log: location of log file for frequent keys [default: STDOUT]
hostname: the hostname of the current machine
(used in conjuction with 'append_hostname') [default: undefined]
append_hostname: when true, statsd will append the hostname to _all_ stats' keys
append_hostname: when true, statsd will append the hostname to _all_ stats' keys
[default: false]
rootDir: root directory for all graphite metrics
[default: 'stats']

*/
{
Expand Down
26 changes: 16 additions & 10 deletions stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ config.configFile(process.argv[2], function (config, oldConfig) {
}, config.debugInterval || 10000);
}

var stat_suffix = ''
var stat_suffix = '';
if (config.hostname && (config.append_hostname || false)) {
stat_suffix = '.' + config.hostname;
if (config.debug) {
util.log("Using hostname as suffix: " + stat_suffix)
util.log("Using hostname as suffix: " + stat_suffix);
}
}

// grab rootDir graphite directory from config or default to 'stats'
var rootDir = config.rootDir || 'stats';
if (config.debug) {
util.log("Using root directory: " + rootDir);
}


if (server === undefined) {

Expand Down Expand Up @@ -207,8 +213,8 @@ config.configFile(process.argv[2], function (config, oldConfig) {
var value = counters[key];
var valuePerSecond = value / (flushInterval / 1000); // calculate "per second" rate

statString += 'stats.' + key + stat_suffix + ' ' + valuePerSecond + ' ' + ts + "\n";
statString += 'stats_counts.' + key + stat_suffix + ' ' + value + ' ' + ts + "\n";
statString += rootDir + '.' + key + stat_suffix + ' ' + valuePerSecond + ' ' + ts + "\n";
statString += rootDir + '_counts.' + key + stat_suffix + ' ' + value + ' ' + ts + "\n";

counters[key] = 0;
numStats += 1;
Expand Down Expand Up @@ -247,23 +253,23 @@ config.configFile(process.argv[2], function (config, oldConfig) {

var clean_pct = '' + pct;
clean_pct.replace('.', '_');
message += 'stats.timers.' + key + stat_suffix + '.mean_' + clean_pct + ' ' + mean + ' ' + ts + "\n";
message += 'stats.timers.' + key + stat_suffix + '.upper_' + clean_pct + ' ' + maxAtThreshold + ' ' + ts + "\n";
message += rootDir + '.timers.' + key + stat_suffix + '.mean_' + clean_pct + ' ' + mean + ' ' + ts + "\n";
message += rootDir + '.timers.' + key + stat_suffix + '.upper_' + clean_pct + ' ' + maxAtThreshold + ' ' + ts + "\n";
}

timers[key] = [];

message += 'stats.timers.' + key + stat_suffix + '.upper ' + max + ' ' + ts + "\n";
message += 'stats.timers.' + key + stat_suffix + '.lower ' + min + ' ' + ts + "\n";
message += 'stats.timers.' + key + stat_suffix + '.count ' + count + ' ' + ts + "\n";
message += rootDir + '.timers.' + key + stat_suffix + '.upper ' + max + ' ' + ts + "\n";
message += rootDir + '.timers.' + key + stat_suffix + '.lower ' + min + ' ' + ts + "\n";
message += rootDir + '.timers.' + key + stat_suffix + '.count ' + count + ' ' + ts + "\n";
statString += message;

numStats += 1;
}
}

for (key in gauges) {
statString += 'stats.gauges.' + key + stat_suffix + ' ' + gauges[key] + ' ' + ts + "\n";
statString += rootDir + '.gauges.' + key + stat_suffix + ' ' + gauges[key] + ' ' + ts + "\n";
numStats += 1;
}

Expand Down