• Stars
    star
    172
  • Rank 220,619 (Top 5 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created almost 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A naive InfluxDB backend for StatsD

StatsD InfluxDB backend

LOOKING FOR A MAINTAINER: I am looking for a maintainer for this project

A naive InfluxDB backend for StatsD.

It can ship events to InfluxDB using two different strategies which can be used at the same time.

Regular Flush Strategy

StatsD will flush aggregated metrics with a configured interval. This is the regular StatsD mode of operation.

Proxy Strategy

This will map every incoming StatsD packet to an InfluxDB event. It's useful if you want to store the raw events in InfluxDB without any rollups.

CAVEATS

This is pretty young and I do not have much experience with InfluxDB yet. Especially the event buffering and the event mapping might be problematic and inefficient.

InfluxDB is also pretty young and there might be breaking changes until it reaches 1.0.

Please be careful!

Installation

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

Configuration

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" ],

  influxdb: {
    host: '127.0.0.1',   // InfluxDB host. (default 127.0.0.1)
    port: 8086,          // InfluxDB port. (default 8086)
    version: 0.8,        // InfluxDB version. (default 0.8)
    ssl: false,          // InfluxDB is hosted over SSL. (default false)
    database: 'dbname',  // InfluxDB database instance. (required)
    username: 'user',    // InfluxDB database username.
    password: 'pass',    // InfluxDB database password.
    flush: {
      enable: true       // Enable regular flush strategy. (default true)
    },
    proxy: {
      enable: false,       // Enable the proxy strategy. (default false)
      suffix: 'raw',       // Metric name suffix. (default 'raw')
      flushInterval: 1000  // Flush interval for the internal buffer.
                           // (default 1000)
    },
    includeStatsdMetrics: false, // Send internal statsd metrics to InfluxDB. (default false)
    includeInfluxdbMetrics: false // Send internal backend metrics to InfluxDB. (default false)
                                  // Requires includeStatsdMetrics to be enabled.
  }
}

Activation

Add the statsd-influxdb-backend to the list of StatsD backends in the config file and restart the StatsD process.

{
  backends: ['./backends/graphite', 'statsd-influxdb-backend']
}

Unsupported Metric Types

Proxy Strategy

  • Counter with sampling.
  • Signed gauges. (i.e. bytes:+4|g)
  • Sets

InfluxDB Event Mapping

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:

[
  {
    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

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

Counter

StatsD packet requests:1|c as InfluxDB event:

Flush Strategy

[
  {
    name: 'requests.counter',
    columns: ['value', 'time'],
    points: [[802, 1384798553000]]
  }
]

Proxy Strategy

[
  {
    name: 'requests.counter.raw',
    columns: ['value', 'time'],
    points: [[1, 1384472029572]]
  }
]

Timing

StatsD packet response_time:170|ms as InfluxDB event:

Flush Strategy

[
  {
    name: 'response_time.timer.mean_90',
    columns: ['value', 'time'],
    points: [[445.25761772853184, 1384798553000]]
  },
  {
    name: 'response_time.timer.upper_90',
    columns: ['value', 'time'],
    points: [[905, 1384798553000]]
  },
  {
    name: 'response_time.timer.sum_90',
    columns: ['value', 'time'],
    points: [[321476, 1384798553000]]
  },
  {
    name: 'response_time.timer.std',
    columns: ['value', 'time'],
    points: [[294.4171159604542, 1384798553000]]
  },
  {
    name: 'response_time.timer.upper',
    columns: ['value', 'time'],
    points: [[998, 1384798553000]]
  },
  {
    name: 'response_time.timer.lower',
    columns: ['value', 'time'],
    points: [[2, 1384798553000]]
  },
  {
    name: 'response_time.timer.count',
    columns: ['value', 'time'],
    points: [[802, 1384798553000]]
  },
  {
    name: 'response_time.timer.count_ps',
    columns: ['value', 'time'],
    points: [[80.2, 1384798553000]]
  },
  {
    name: 'response_time.timer.sum',
    columns: ['value', 'time'],
    points: [[397501, 1384798553000]]
  },
  {
    name: 'response_time.timer.mean',
    columns: ['value', 'time'],
    points: [[495.6371571072319, 1384798553000]]
  },
  {
    name: 'response_time.timer.median',
    columns: ['value', 'time'],
    points: [[483, 1384798553000]]
  }
]

Proxy Strategy

[
  {
    name: 'response_time.timer.raw',
    columns: ['value', 'time'],
    points: [[170, 1384472029572]]
  }
]

Gauges

StatsD packet bytes:123|g as InfluxDB event:

Flush Strategy

[
  {
    name: 'bytes.gauge',
    columns: ['value', 'time'],
    points: [[123, 1384798553000]]
  }
]

Proxy Strategy

[
  {
    name: 'bytes.gauge.raw',
    columns: ['value', 'time'],
    points: [['gauge', 123, 1384472029572]]
  }
]

Proxy Strategy Notes

Event Buffering

To avoid one HTTP request per StatsD packet, the InfluxDB backend buffers the incoming events and flushes the buffer on a regular basis. The current default is 1000ms. Use the influxdb.proxy.flushInterval to change the interval.

This might become a problem with lots of incoming events.

The payload of a HTTP request might look like this:

[
  {
    name: 'requests.counter.raw',
    columns: ['value', 'time'],
    points: [
      [1, 1384472029572],
      [1, 1384472029573],
      [1, 1384472029580]
    ]
  },
  {
    name: 'response_time.timer.raw',
    columns: ['value', 'time'],
    points: [
      [170, 1384472029570],
      [189, 1384472029572],
      [234, 1384472029578],
      [135, 1384472029585]
    ]
  },
  {
    name: 'bytes.gauge.raw',
    columns: ['value', 'time'],
    points: [
      [123, 1384472029572],
      [123, 1384472029580]
    ]
  }
]

Backend Metrics

The following internal metrics are calculated for each flush:

  • statsd.influxdbStats.flush_time - Time taken to process a complete flush in ms. Excluding the asynchronous HTTP Post.
  • statsd.influxdbStats.http_response_time - Response time in ms of the InfluxDB HTTP endpoint when POSTing data.
  • statsd.influxdbStats.payload_size - The size in bytes of the JSON payload.
  • statsd.influxdbStats.num_stats - The number of metrics sent to InfluxDB in the last flush.

These are added to the set of internal statsd metrics. If both influxdb.includeStatsdMetrics and influxdb.includeInfluxdbMetrics are enabled, then these will be sent to InfluxDB when using the flush strategy.

The internal metrics can also can be viewed using the stats command on the StatsD TCP Admin Interface

Contributing

All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.

More Repositories

1

fpm-cookery

A tool for building software packages with fpm.
Ruby
459
star
2

fpm-recipes

My collection of fpm-cookery recipes.
Ruby
145
star
3

cucumber-sinatra

Initialize a cucumber environment for sinatra.
Ruby
64
star
4

discourse-slack-plugin

Send notifications to slack for new topics in discourse
Ruby
41
star
5

nagios_parser

Ruby library for parsing Nagios status and config files
Ruby
31
star
6

librrd-ruby

Ruby bindings for librrd. Extracted from the RRDtool source.
C
18
star
7

spotify-backup

Backup Spotify saved tracks, artists and playlists
Ruby
12
star
8

webmachine-test

A testing API for webmachine-ruby.
Ruby
10
star
9

dcell-hazelcast

Hazelcast registry for DCell
Ruby
7
star
10

ruby-upstart

Ruby library to inspect and control the Ubuntu Upstart daemon.
Ruby
7
star
11

wunderlist-backup

Backup your Wunderlist data
Ruby
6
star
12

dropreact

Example Dropwizard & React application
JavaScript
4
star
13

smstraderb

Ruby client library for the smstrade.de HTTP API
Ruby
4
star
14

samsa

Pure Java port of the Kafka Log and LogManager
Java
3
star
15

as-notifications

extraction of ActiveSupport::Notifications from Ruby on Rails
Ruby
3
star
16

roboter

A robot framework. (WIP)
Ruby
2
star
17

dot.vim

My vim configuration
Vim Script
2
star
18

statsd-kairosdb-backend

KairosDB backend for StatsD
JavaScript
2
star
19

spinoff

Spinoff preloads your Ruby environment based on an initialization file.
Ruby
2
star
20

react-typescript-example

React + typescript
JavaScript
1
star
21

slides-rrdtool-rug-hh

Slides of my Rails User Group HH talk (german)
Ruby
1
star
22

guard-spinoff

Guard integration for Spinoff
Ruby
1
star
23

jsonserver

A simple server that accepts and prints pretty-printed JSON to STDOUT
Java
1
star
24

cucumber-puppet

Specifying Puppet catalog behavior with Cucumber
Ruby
1
star
25

eventmachine

EventMachine: fast, simple event-processing library for Ruby programs
Ruby
1
star