etsy/statsd — pull request #345 by urlgrey (2013-09-26 16:07:20+00:00)
Title: Add Graphite backend configuration flag to connect only when there are metrics to send

The Statsd Graphite backend in the master branch will connect to a Graphite carbon-relay or carbon-cache server even when there are no metrics to report. This can be useful for indicating that the Statsd process is alive and well, and capable of sending metrics if/when they occur; however, the frequency & volume of connections to Graphite could become a problem in some circumstances.

In my case, I have a large number of Amazon EC2 instances that can perform various tasks. Statsd metrics are generated for just one type of task. Using the master branch of Statsd, all EC2 instances connect to the Graphite server at 1 second intervals, usually reporting no metrics. I would prefer to have just the instances handling the task that produces metrics connect to Graphite and report stats. My applications produces several Statsd gauge values while the task is running.

I have added a 'quiet' boolean flag to the Statsd Graphite configuration. It has a default value of 'false', which will cause the Graphite backend to perform identically to the current master branch (always connect to Graphite). If the 'quiet' flag is set to 'true', then a connection will be made to Graphite only when there are metrics to report.

Here's an example Statsd config.js file showing its usage:

```
{
graphitePort: "2013"
, graphiteHost: "x.x.x.x"
, flushInterval: "1000"
, port: 8125
, backends: [ "./backends/graphite" ]
, graphite: { quiet: true }
, deleteIdleStats: true
}
```