Skip to content

Commit

Permalink
implement tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerxes committed Jan 5, 2018
1 parent 25f7924 commit dd8780d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/GraphiteClient.js
Expand Up @@ -28,6 +28,22 @@ GraphiteClient.flatten = function(obj, flat, prefix) {
return flat;
};

GraphiteClient.appendTags = function(flatMetrics, tags) {
tagSuffix = '';
res = {};

flatTags = GraphiteClient.flatten(tags);
for (var key in flatTags) {
tagSuffix += ';' + key + '=' + flatTags[key];
}

for (var key in flatMetrics) {
res[key + tagSuffix] = flatMetrics[key];
}

return res;
}

GraphiteClient.prototype.write = function(metrics, timestamp, cb) {
if (typeof timestamp === 'function') {
cb = timestamp;
Expand All @@ -40,6 +56,11 @@ GraphiteClient.prototype.write = function(metrics, timestamp, cb) {
this._carbon.write(GraphiteClient.flatten(metrics), timestamp, cb);
};

GraphiteClient.prototype.writeTagged = function(metrics, tags, timestamp, cb) {
taggedMetrics = appendTags(GraphiteClient.flatten(metrics), tags);
this.write(taggedMetrics, timestamp, cb);
}

GraphiteClient.prototype.end = function() {
this._carbon.end();
};

0 comments on commit dd8780d

Please sign in to comment.