etsy/statsd — pull request #69 by mheffner (2012-04-02 19:48:43+00:00)
Title: Feature: Backends as modules

Opening this PR for feedback on the first part of series of patchsets to split up the original pull request #56: Batched send, reliability fixes, multiple graphing backends, package.json.

This PR splits out the backend persistence code for Graphite into a simple module file under a backends directory. The idea is that each backend (e.g. Graphite, Librato Metrics, etc.) implements a simple module API that handles all persistence of the statsd metrics to an appropriate backend data store or service.

This patchset adds the configuration variable `backends` that should be set to an array of module names located in the 'backends/' directory. For each module listed in the config file, statsd will load and initialize the module and flush stats to it during each flush interval. For backwards compatibility, if this is not set then the single 'graphite' backend module will be loaded.

A backend module should export the following functions:

* `init(startup_time, config)`: This is invoked when the module is loaded. It should return a function callback with signature `f(time_stamp, flushInterval, metrics)` that will be invoked each time statsd flushes metrics to this backend.
* `write_stats(writeCb)`: This method is invoked when a user performs a *stats* command on the management server port and it allows the backend to dump backend-specific stats to the management port. The `writeCb` has a signature of `(stat_name, stat_value)`.