Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Monitoring] Enable statsd middleware to push metrics #3613

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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