Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #49 from fanhattan/fanhattan_globalprefix
Browse files Browse the repository at this point in the history
Added globalPrefix configuration option.
  • Loading branch information
mheffner committed Jan 16, 2015
2 parents a292145 + 7860c49 commit 5caef74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ options under the top-level `librato` hash:
}
```

* `globalPrefix`: A string to prepend to all measurement names sent to Librato. If set, a dot
will automatically be added as separator between prefix and measurement name.

## Reducing published data for inactive stats

By default StatsD will push a zero value for any counter that does not
Expand Down
13 changes: 10 additions & 3 deletions lib/librato.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ var libratoCounters = {};
// e.g. metric_name.100
var alwaysSuffixPercentile = false;

// A string to prepend to all measurement names sent to Librato.
var globalPrefix = "";

var post_payload = function(options, proto, payload, retry)
{
var req = proto.request(options, function(res) {
Expand Down Expand Up @@ -227,10 +230,10 @@ var flush_stats = function librato_flush(ts, metrics)
if (sourceRegex && (match = measure.name.match(sourceRegex)) && match[1]) {
// Use first capturing group as source name
measure.source = sanitize_name(match[1]);
// Remove entire matching string from the measure name
measure.name = sanitize_name(measure.name.slice(0, match.index) + measure.name.slice(match.index + match[0].length));
// Remove entire matching string from the measure name & add global prefix.
measure.name = globalPrefix + sanitize_name(measure.name.slice(0, match.index) + measure.name.slice(match.index + match[0].length));
} else {
measure.name = sanitize_name(measure.name);
measure.name = globalPrefix + sanitize_name(measure.name);
}

if (mType == 'counter') {
Expand Down Expand Up @@ -524,6 +527,10 @@ exports.init = function librato_init(startup_time, config, events, logger)
if(config.librato.alwaysSuffixPercentile) {
alwaysSuffixPercentile = config.librato.alwaysSuffixPercentile;
}

if(config.librato.globalPrefix) {
globalPrefix = config.librato.globalPrefix + '.';
}
}

if (!email || !token) {
Expand Down

0 comments on commit 5caef74

Please sign in to comment.