Skip to content

Commit

Permalink
Add SET support.
Browse files Browse the repository at this point in the history
Squashed commit compiled from #7. All work by @kureikain.

Fixes #7.
  • Loading branch information
bernd committed Feb 22, 2015
1 parent 745a5e5 commit 33a682c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ file and restart the StatsD process.

## Unsupported Metric Types

#### Flush Strategy

* Sets

#### Proxy Strategy

* Counter with sampling.
Expand All @@ -92,6 +88,40 @@ file and restart the StatsD process.
StatsD packets are currently mapped to the following InfluxDB events. This is
a first try and I'm open to suggestions to improve this.

### Set

StatsD package `client_version:1.1|c`, `client_version:1.2|c` as Influx event:

```js
[
{
name: 'visior',
columns: ['value', 'time'],
points: [['1.1', 1384798553000], ['1.2', 1384798553001]]
}
]
```

If you are using Grafana to visualize a Set, then using this query or
something similar

```
SELECT version, count(version) FROM client_version GROUP BY version, time(1m)
```

Also, to count for the size of unique value, another InfluxDB event is
also pushed

```js
[
{
name: 'visitor_count',
columns: ['value', 'time'],
points: [set.length, 1384798553001]
}
]
```

### Counter

StatsD packet `requests:1|c` as InfluxDB event:
Expand Down
20 changes: 20 additions & 0 deletions lib/influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,25 @@ InfluxdbBackend.prototype.logDebug = function (msg) {
}
}

/**
* Flush strategy handler
*
* @param {Number} timestamp
* @param {Object} stats metric
*/
InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {
var self = this,
counters = metrics.counters,
gauges = metrics.gauges,
timerData = metrics.timer_data,
points = [],
sets = function (vals) {
var ret = {};
for (var val in vals) {
ret[val] = vals[val].values();
}
return ret;
}(metrics.sets),
key, timerKey;

/* Convert timestamp from seconds to milliseconds. */
Expand All @@ -145,6 +158,13 @@ InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {
}
}

for (set in sets) {
sets[set].map(function (v) {
points.push(self.assembleEvent(set, [{value: v, time: timestamp}]));
})
points.push(self.assembleEvent(set + "_count", [{value: sets[set].length, time: timestamp}]));
}

for (key in gauges) {
var value = gauges[key],
k = key + '.gauge';
Expand Down

0 comments on commit 33a682c

Please sign in to comment.