Skip to content

Commit

Permalink
Merge branch 'master' into fix-timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Serphentas authored Jan 14, 2018
2 parents e8a4c2a + a349370 commit c502c87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ client.write(metrics, timestamp, function(err) {
});
```

In Graphite [1.1.1 (21.12.17)](http://graphite.readthedocs.io/en/latest/releases/1_1_1.html), [tagging](http://graphite.readthedocs.io/en/latest/tags.html) becomes available. You can send tagged metrics as follows:

```js
var metrics = {foo: 23};
var tags = {'name': 'foo.bar', 'some.fancy.tag': 'somefancyvalue'};
client.writeTagged(metrics, tags, function(err) {
// if err is null, your data was sent to graphite!
});
```

## Todo

* More docs
Expand Down
21 changes: 21 additions & 0 deletions lib/GraphiteClient.js
Original file line number Diff line number Diff line change
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;
};

/**
* Writes the given metrics to the underlying plaintext socket to Graphite
*
Expand All @@ -52,6 +68,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 = GraphiteClient.appendTags(GraphiteClient.flatten(metrics), tags);
this.write(taggedMetrics, timestamp, cb);
}

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

0 comments on commit c502c87

Please sign in to comment.