Skip to content

Commit 6036d41

Browse files
authored
Backend: Add statsd middleware for metrics push (#3613)
1 parent f62dfd0 commit 6036d41

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22

33
from django.utils.deprecation import MiddlewareMixin
4-
# from monitoring.statsd.metrics import statsd, REQUEST_COUNT_METRIC_NAME, REQUEST_LATENCY_METRIC_NAME
4+
from monitoring.statsd.metrics import statsd, REQUEST_COUNT_METRIC_NAME, REQUEST_LATENCY_METRIC_NAME
55

66

77
class StatsdMetricsMiddleware(MiddlewareMixin):
@@ -17,26 +17,24 @@ def get_view_name(self, request):
1717
return view_name
1818

1919
def process_response(self, request, response):
20-
# TODO: Enable statsd metric push once production docker setup is ready
21-
# statsd.increment(
22-
# REQUEST_COUNT_METRIC_NAME,
23-
# tags=[
24-
# "service:django_worker",
25-
# "method:%s" % request.method,
26-
# "view:%s" % self.get_view_name(request),
27-
# "status:%s" % str(response.status_code),
28-
# ],
29-
# )
30-
31-
# resp_time = (time.time() - request.start_time) * 1000
32-
33-
# statsd.histogram(
34-
# REQUEST_LATENCY_METRIC_NAME,
35-
# resp_time,
36-
# tags=[
37-
# "service:django_worker",
38-
# "view:%s" % self.get_view_name(request),
39-
# ],
40-
# )
41-
20+
statsd.increment(
21+
REQUEST_COUNT_METRIC_NAME,
22+
tags=[
23+
"service:django_worker",
24+
"method:%s" % request.method,
25+
"view:%s" % self.get_view_name(request),
26+
"status:%s" % str(response.status_code),
27+
],
28+
)
29+
30+
resp_time = (time.time() - request.start_time) * 1000
31+
32+
statsd.histogram(
33+
REQUEST_LATENCY_METRIC_NAME,
34+
resp_time,
35+
tags=[
36+
"service:django_worker",
37+
"view:%s" % self.get_view_name(request),
38+
],
39+
)
4240
return response

monitoring/statsd/metrics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@
1414

1515

1616
def increment_statsd_counter(metric_name, tags, inc_value):
17-
# TODO: Enable statsd metric increment once production docker setup is ready
18-
# statsd.increment(metric_name, inc_value, tags=tags)
17+
statsd.increment(metric_name, inc_value, tags=tags)
1918
return

0 commit comments

Comments
 (0)