Skip to content

Commit

Permalink
Merge branch 'fix-timestamp' of ssh://github.com/Serphentas/node-grap…
Browse files Browse the repository at this point in the history
…hite into fix-timestamp
  • Loading branch information
Serphentas committed Jan 14, 2018
2 parents 0736a8b + c502c87 commit b93d73b
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 b93d73b

Please sign in to comment.