Switch durations from milliseconds to seconds.

This commit is contained in:
Dave Shawley 2016-01-19 11:14:02 -05:00
parent 3e056878a8
commit db0723ad72
2 changed files with 30 additions and 10 deletions

View file

@ -10,17 +10,37 @@ implements the same interface:
Key in ``self.application.settings`` that contains this particular
mix-in's configuration data.
.. method:: record_timing(milliseconds, *path)
.. method:: record_timing(duration, *path)
:noindex:
:param float milliseconds: number of milliseconds to record
:param float duration: number of seconds to record
:param path: timing path to record
.. code-block:: python
self.record_timing(self.request.request_time(), 'request', 'lookup')
.. method:: increase_counter(*path, amount=1)
:param path: counter path to increment
:keyword int amount: value to increase the counter by
.. code-block:: python
self.increase_counter('db', 'query', 'foo')
.. method:: execution_timer(*path)
:param path: timing path to record
This method returns a context manager that records a timing
metric to the specified path.
.. code-block:: python
with self.execution_timer('db', 'query', 'foo'):
rows = yield self.session.query('SELECT * FROM foo')
Statsd Implementation
---------------------

View file

@ -45,11 +45,11 @@ class StatsdMixin(object):
self.__status_code = status_code
super(StatsdMixin, self).set_status(status_code, reason=reason)
def record_timing(self, milliseconds, *path):
def record_timing(self, duration, *path):
"""
Record a timing.
:param float milliseconds: millisecond timing to record
:param float duration: timing to record in seconds
:param path: elements of the metric path to record
This method records a timing to the application's namespace
@ -59,7 +59,7 @@ class StatsdMixin(object):
more than replacing periods with dashes.
"""
self._send(self._build_path(path), milliseconds, 'ms')
self._send(self._build_path(path), duration * 1000.0, 'ms')
def increase_counter(self, *path, **kwargs):
"""
@ -95,22 +95,22 @@ class StatsdMixin(object):
yield
finally:
fini = max(start, time.time())
self.record_timing((fini - start) * 1000.0, *path)
self.record_timing(fini - start, *path)
def on_finish(self):
"""
Records the time taken to process the request.
This method records the number of milliseconds that were used
to process the request (as reported by
:meth:`tornado.web.HTTPRequest.request_time` * 1000) under the
This method records the amount of time taken to process the request
(as reported by
:meth:`~tornado.httputil.HTTPServerRequest.request_time`) under the
path defined by the class's module, it's name, the request method,
and the status code. The :meth:`.record_timing` method is used
to send the metric, so the configured namespace is used as well.
"""
super(StatsdMixin, self).on_finish()
self.record_timing(self.request.request_time() * 1000,
self.record_timing(self.request.request_time(),
self.__class__.__name__, self.request.method,
self.__status_code)