Simple daemon for easy stats aggregation with amqp support
JavaScript Java PHP Python Perl Shell
Pull request Compare This branch is 16 commits ahead, 888 commits behind etsy:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
debian
LICENSE
README.md
StatsdClient.java
check_statsd.pl
config.js
exampleConfig.js
php-example.php
python_example.py
stats.js

README.md

StatsD

A network daemon for aggregating statistics (counters and timers), rolling them up, then sending them to graphite.

We (Etsy) blogged about how it works and why we created it.

This fork of statsd can publish to graphite through an AMQP server such as rabbitmq instead of using TCP.

AMQP support requires node-amqp. "npm install amqp" or https://github.com/postwait/node-amqp

Concepts

  • buckets Each stat is in it's own "bucket". They are not predefined anywhere. Buckets can be named anything that will translate to Graphite (periods make folders, etc)

  • values Each stat will have a value. How it is interpreted depends on modifiers

  • flush After the flush interval timeout (default 10 seconds), stats are munged and sent over to Graphite.

Counting

gorets:1|c

This is a simple counter. Add 1 to the "gorets" bucket. It stays in memory until the flush interval config.flushInterval.

Gauging

grud:20|g

Gauges are useful for things like disk and memory usage, or the current measurement from your networked coffee pot scale.

The format for the UDP packet is like the others, except it ends in 'g' instead of in 'ms' or 'c'.

Timing

glork:320|ms

The glork took 320ms to complete this time. StatsD figures out 90th percentile, average (mean), lower and upper bounds for the flush interval. The percentile threshold can be tweaked with config.percentThreshold.

Delayed Timing

glub:320|ms|t1321997890

Instead of statsd sending the timing stats to graphite at the end of the flush interval, StatsD can also delay the write to graphite while additional timer stats arrive. The final parameter is a timestamp in unix time, prefixed with the lowercase letter "t", intended as the time the stats were generated. The number of flush intervals StatsD will wait for timer stats can be configured with config.delayIntervals, the default is 5 minutes or 30 * 10sec flush intervals.

Sampling

gorets:1|c|@0.1

Tells StatsD that this counter is being sent sampled every 1/10th of the time.

Debugging

There are additional config variables available for debugging:

  • debug - log exceptions and periodically print out information on counters and timers
  • debugInterval - interval for printing out information on counters and timers
  • dumpMessages - print debug info on incoming messages

For more information, check the exampleConfig.js.

Guts

  • UDP Client libraries use UDP to send information to the StatsD daemon.

  • NodeJS

  • Graphite

Graphite uses "schemas" to define the different round robin datasets it houses (analogous to RRAs in rrdtool). Here's what Etsy is using for the stats databases:

[stats]
priority = 110
pattern = ^stats\..*
retentions = 10:2160,60:10080,600:262974

That translates to:

  • 6 hours of 10 second data (what we consider "near-realtime")
  • 1 week of 1 minute data
  • 5 years of 10 minute data

This has been a good tradeoff so far between size-of-file (round robin databases are fixed size) and data we care about. Each "stats" database is about 3.2 megs with these retentions.

TCP Stats Interface

A really simple TCP management interface is available by default on port 8126 or overriden in the configuration file. Inspired by the memcache stats approach this can be used to monitor a live statsd server. You can interact with the management server by telnetting to port 8126, the following commands are available:

  • stats - some stats about the running server
  • counters - a dump of all the current counters
  • timers - a dump of the current timers
  • gauges - a dump of the current gauges
  • dtimers - a dump of the current dtimers

The stats output currently will give you:

  • uptime: the number of seconds elapsed since statsd started
  • graphite.last_flush: the number of seconds elapsed since the last successful flush to graphite
  • graphite.last_exception: the number of seconds elapsed since the last exception thrown whilst flushing to graphite
  • messages.last_msg_seen: the number of elapsed seconds since statsd received a message
  • messages.bad_lines_seen: the number of bad lines seen since startup

Installation and Configuration

  • Install node.js
  • Clone the project
  • Create a config file from exampleConfig.js and put it somewhere
  • Start the Daemon:

    node stats.js /path/to/config

Inspiration

StatsD was inspired (heavily) by the project (of the same name) at Flickr. Here's a post where Cal Henderson described it in depth: Counting and timing. Cal re-released the code recently: Perl StatsD

Contribute

You're interested in contributing to StatsD? AWESOME. Here are the basic steps:

fork StatsD from here: http://github.com/etsy/statsd

  1. Clone your fork
  2. Hack away
  3. If you are adding new functionality, document it in the README
  4. If necessary, rebase your commits into logical chunks, without errors
  5. Push the branch up to GitHub
  6. Send a pull request to the etsy/statsd project.

We'll do our best to get your changes in!

Contributors

In lieu of a list of contributors, check out the commit history for the project: http://github.com/etsy/statsd/commits/master