mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Added statsd integration into the API
- new client for statsd, follows conventions used elsewhere for configuration - client wraps underlying library so we can use a config property to send/not send statsd Added statsd metrics for: - count of API successful calls SMS/Email - count of successful task execution for SMS/Email - count of errors from Client libraries - timing of API calls to third party clients - timing of how long messages live on the SQS queue
This commit is contained in:
26
app/clients/statsd/statsd_client.py
Normal file
26
app/clients/statsd/statsd_client.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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')
|
||||
|
||||
def incr(self, stat, count=1, rate=1):
|
||||
if self.active:
|
||||
super(StatsClient, self).incr(stat, count, rate)
|
||||
|
||||
def timing(self, stat, delta, rate=1):
|
||||
if self.active:
|
||||
super(StatsClient, self).timing(stat, delta, rate)
|
||||
|
||||
|
||||
def timing_with_dates(self, stat, start, end, rate=1):
|
||||
if self.active:
|
||||
delta = (start - end).total_seconds() * 1000
|
||||
super(StatsClient, self).timing(stat, delta, rate)
|
||||
Reference in New Issue
Block a user