Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SET support #7

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
StatsD InfluxDB backend - CHANGELOG
-----------------------------------
## v0.4.0(2014-12-10)
* Add support for SET

## v0.3.0 (2014-08-24)

Expand Down
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
StatsD InfluxDB backend
-----------------------

Fork of https://github.com/bernd/statsd-influxdb-backend to support SET
and continue maintenance. `furu` means full in Japanese.


A naive [InfluxDB](http://influxdb.org/) backend for
[StatsD](https://github.com/etsy/statsd).

Expand Down Expand Up @@ -31,7 +35,7 @@ Please be careful!
## Installation

$ cd /path/to/statsd
$ npm install statsd-influxdb-backend
$ npm install statsd-influxdb-furu

## Configuration

Expand All @@ -42,7 +46,7 @@ You can configure the following settings in your StatsD config file.
graphitePort: 2003,
graphiteHost: "graphite.example.com",
port: 8125,
backends: [ "./backends/graphite", "statsd-influxdb-backend" ],
backends: [ "./backends/graphite", "statsd-influxdb-furu" ],

influxdb: {
host: '127.0.0.1', // InfluxDB host. (default 127.0.0.1)
Expand Down Expand Up @@ -77,10 +81,6 @@ file and restart the StatsD process.

## Unsupported Metric Types

#### Flush Strategy

* Sets

#### Proxy Strategy

* Counter with sampling.
Expand All @@ -92,6 +92,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
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "statsd-influxdb-backend",
"version": "0.3.0",
"name": "statsd-influxdb-furu",
"version": "0.5.1",
"description": "InfluxDB backend for StatsD",
"main": "lib/influxdb.js",
"dependencies": {
Expand All @@ -10,16 +10,17 @@
},
"repository": {
"type": "git",
"url": "git://github.com/bernd/statsd-influxdb-backend.git"
"url": "git://github.com/kureikain/statsd-influxdb-backend.git"
},
"keywords": [
"influxdb",
"statsd",
"metrics"
],
"author": "Bernd Ahlers <bernd@tuneafish.de>",
"contributors": "Vinh Quốc Nguyễn kurei@axcoto.com",
"license": "BSD",
"bugs": {
"url": "https://github.com/bernd/statsd-influxdb-backend/issues"
"url": "https://github.com/kureikain/statsd-influxdb-backend/issues"
}
}