Files
notifications-api/app/clients/statsd/statsd_client.py
Martyn Inglis 6b12c397a1 Ensure that configs know which environment it is.
This allows us to prefix metrics with the environment to allow stats from staging and live to go to the same statsd, and alls us to filter in the dashboard by environment.
2016-08-08 10:20:33 +01:00

25 lines
830 B
Python

from statsd import StatsClient
class StatsdClient(StatsClient):
def init_app(self, app, *args, **kwargs):
StatsClient.__init__(
self,
app.config.get('STATSD_HOST'),
app.config.get('STATSD_PORT'),
prefix=app.config.get('STATSD_PREFIX')
)
self.active = app.config.get('STATSD_ENABLED')
self.namespace = app.config.get('NOTIFY_ENVIRONMENT') + ".notifications.api."
def format_stat_name(self, stat):
return self.namespace + stat
def incr(self, stat, count=1, rate=1):
if self.active:
super(StatsClient, self).incr(self.format_stat_name(stat), count, rate)
def timing(self, stat, delta, rate=1):
if self.active:
super(StatsClient, self).timing(self.format_stat_name(stat), delta, rate)