From 7c10c7d22d49c09e4fd8733da747b288384ee361 Mon Sep 17 00:00:00 2001 From: Matt Good Date: Sun, 3 Aug 2014 13:38:07 -0700 Subject: [PATCH 1/2] Send statsd timing metrics in milliseconds The statsd documentation indicates that timing values are expected to be in milliseconds, not seconds: "The glork took 320ms to complete this time" https://github.com/etsy/statsd/blob/master/docs/metric_types.md#timing --- gunicorn/instrument/statsd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gunicorn/instrument/statsd.py b/gunicorn/instrument/statsd.py index e712c47f..5dfe14fa 100644 --- a/gunicorn/instrument/statsd.py +++ b/gunicorn/instrument/statsd.py @@ -81,8 +81,8 @@ class Statsd(Logger): request_time is a datetime.timedelta """ Logger.access(self, resp, req, environ, request_time) - duration_in_s = request_time.seconds + float(request_time.microseconds)/10**6 - self.histogram("gunicorn.request.duration", duration_in_s) + duration_in_ms = request_time.seconds * 1000 + float(request_time.microseconds)/10**3 + self.histogram("gunicorn.request.duration", duration_in_ms) self.increment("gunicorn.requests", 1) self.increment("gunicorn.request.status.%d" % int(resp.status.split()[0]), 1) From 59bf9b5867b0c722c7107645952eb5f71845f20a Mon Sep 17 00:00:00 2001 From: Matt Good Date: Sun, 3 Aug 2014 14:39:34 -0700 Subject: [PATCH 2/2] Fix statsd test for millisecond times --- tests/test_010-statsd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_010-statsd.py b/tests/test_010-statsd.py index aaf75dd5..70f7ea73 100644 --- a/tests/test_010-statsd.py +++ b/tests/test_010-statsd.py @@ -49,6 +49,6 @@ def test_instrument(): logger.sock.reset() logger.access(MockResponse("200 OK"), None, {}, timedelta(seconds=7)) - t.eq(logger.sock.msgs[0], "gunicorn.request.duration:7.0|ms") + t.eq(logger.sock.msgs[0], "gunicorn.request.duration:7000.0|ms") t.eq(logger.sock.msgs[1], "gunicorn.requests:1|c|@1.0") t.eq(logger.sock.msgs[2], "gunicorn.request.status.200:1|c|@1.0")