Skip to content

Commit

Permalink
Backend: Add statsd middleware for metrics push (Cloud-CV#3613)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ram81 authored Oct 13, 2021
1 parent 880329b commit aac446b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
44 changes: 21 additions & 23 deletions middleware/statsd/statsd_middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time

from django.utils.deprecation import MiddlewareMixin
# from monitoring.statsd.metrics import statsd, REQUEST_COUNT_METRIC_NAME, REQUEST_LATENCY_METRIC_NAME
from monitoring.statsd.metrics import statsd, REQUEST_COUNT_METRIC_NAME, REQUEST_LATENCY_METRIC_NAME


class StatsdMetricsMiddleware(MiddlewareMixin):
Expand All @@ -17,26 +17,24 @@ def get_view_name(self, request):
return view_name

def process_response(self, request, response):
# TODO: Enable statsd metric push once production docker setup is ready
# statsd.increment(
# REQUEST_COUNT_METRIC_NAME,
# tags=[
# "service:django_worker",
# "method:%s" % request.method,
# "view:%s" % self.get_view_name(request),
# "status:%s" % str(response.status_code),
# ],
# )

# resp_time = (time.time() - request.start_time) * 1000

# statsd.histogram(
# REQUEST_LATENCY_METRIC_NAME,
# resp_time,
# tags=[
# "service:django_worker",
# "view:%s" % self.get_view_name(request),
# ],
# )

statsd.increment(
REQUEST_COUNT_METRIC_NAME,
tags=[
"service:django_worker",
"method:%s" % request.method,
"view:%s" % self.get_view_name(request),
"status:%s" % str(response.status_code),
],
)

resp_time = (time.time() - request.start_time) * 1000

statsd.histogram(
REQUEST_LATENCY_METRIC_NAME,
resp_time,
tags=[
"service:django_worker",
"view:%s" % self.get_view_name(request),
],
)
return response
3 changes: 1 addition & 2 deletions monitoring/statsd/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@


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

0 comments on commit aac446b

Please sign in to comment.