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

Improve metrics reporting #672

Merged
merged 2 commits into from
Sep 7, 2018
Merged
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
11 changes: 8 additions & 3 deletions connexion/decorators/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import time

from werkzeug.exceptions import HTTPException

try:
import uwsgi_metrics
HAS_UWSGI_METRICS = True # pragma: no cover
Expand Down Expand Up @@ -30,16 +32,19 @@ def __call__(self, function):

@functools.wraps(function)
def wrapper(request):
status_code = 500
status = 500
start_time_s = time.time()
try:
response = function(request)
status_code = response.status_code
status = response.status_code
except HTTPException as http_e:
status = http_e.code
raise http_e
finally:
end_time_s = time.time()
delta_s = end_time_s - start_time_s
delta_ms = delta_s * 1000
key = '{status}.{suffix}'.format(status=status_code, suffix=self.key_suffix)
key = '{status}.{suffix}'.format(status=status, suffix=self.key_suffix)
uwsgi_metrics.timer(self.prefix, key, delta_ms)
return response

Expand Down