mailgun/pylemma — pull request #3 by russjones (2014-12-05 02:09:17+00:00)
Title: Emit stats to statsd.

**Purpose**

A good way to look for malicious activity is successful and unsuccessful authentication/encryption events. Currently we have no way of doing this. This commit starts emitting these metrics to statsd. This way we can display it on a dashbaord and if we see a spike of unsuccessful authentication or encryption events we know someone may be trying to attack our system or something is going wrong on our end.

**Implementation**

* Before doing anything else, call `lemma.metrics.initialize` with the hostname and port of the statsd server. Optionally a prefix can be given to prefix all metrics. By deafult this is 'lemma.{hostname}'.
* If you don't call `lemma.metrics.initialize` you can still call the `emit_success` and `emit_failure` methods, but nothing will happen. This is done to keep code clean, so instead of a `if` check every time you want to emit a metric, you can just try to emit the metric. It will be sent if you have the service configured.
* Call `lemma.metrics.emit_success` or `lemma.metrics.emit_failure` whenever you wish to emit a metric. They are thread safe.
* Currently, the above two methods are called by `lemma.httpsign.authenticate_request` and `lemma.httpsign.open`.

**Related Commits**