mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-25 11:19:53 +00:00
Switch durations from milliseconds to seconds.
This commit is contained in:
parent
3e056878a8
commit
db0723ad72
2 changed files with 30 additions and 10 deletions
24
docs/api.rst
24
docs/api.rst
|
@ -10,17 +10,37 @@ implements the same interface:
|
||||||
Key in ``self.application.settings`` that contains this particular
|
Key in ``self.application.settings`` that contains this particular
|
||||||
mix-in's configuration data.
|
mix-in's configuration data.
|
||||||
|
|
||||||
.. method:: record_timing(milliseconds, *path)
|
.. method:: record_timing(duration, *path)
|
||||||
:noindex:
|
:noindex:
|
||||||
|
|
||||||
:param float milliseconds: number of milliseconds to record
|
:param float duration: number of seconds to record
|
||||||
:param path: timing path 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)
|
.. method:: increase_counter(*path, amount=1)
|
||||||
|
|
||||||
:param path: counter path to increment
|
:param path: counter path to increment
|
||||||
:keyword int amount: value to increase the counter by
|
: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
|
Statsd Implementation
|
||||||
---------------------
|
---------------------
|
||||||
|
|
|
@ -45,11 +45,11 @@ class StatsdMixin(object):
|
||||||
self.__status_code = status_code
|
self.__status_code = status_code
|
||||||
super(StatsdMixin, self).set_status(status_code, reason=reason)
|
super(StatsdMixin, self).set_status(status_code, reason=reason)
|
||||||
|
|
||||||
def record_timing(self, milliseconds, *path):
|
def record_timing(self, duration, *path):
|
||||||
"""
|
"""
|
||||||
Record a timing.
|
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
|
:param path: elements of the metric path to record
|
||||||
|
|
||||||
This method records a timing to the application's namespace
|
This method records a timing to the application's namespace
|
||||||
|
@ -59,7 +59,7 @@ class StatsdMixin(object):
|
||||||
more than replacing periods with dashes.
|
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):
|
def increase_counter(self, *path, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -95,22 +95,22 @@ class StatsdMixin(object):
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
fini = max(start, time.time())
|
fini = max(start, time.time())
|
||||||
self.record_timing((fini - start) * 1000.0, *path)
|
self.record_timing(fini - start, *path)
|
||||||
|
|
||||||
def on_finish(self):
|
def on_finish(self):
|
||||||
"""
|
"""
|
||||||
Records the time taken to process the request.
|
Records the time taken to process the request.
|
||||||
|
|
||||||
This method records the number of milliseconds that were used
|
This method records the amount of time taken to process the request
|
||||||
to process the request (as reported by
|
(as reported by
|
||||||
:meth:`tornado.web.HTTPRequest.request_time` * 1000) under the
|
:meth:`~tornado.httputil.HTTPServerRequest.request_time`) under the
|
||||||
path defined by the class's module, it's name, the request method,
|
path defined by the class's module, it's name, the request method,
|
||||||
and the status code. The :meth:`.record_timing` method is used
|
and the status code. The :meth:`.record_timing` method is used
|
||||||
to send the metric, so the configured namespace is used as well.
|
to send the metric, so the configured namespace is used as well.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super(StatsdMixin, self).on_finish()
|
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.__class__.__name__, self.request.method,
|
||||||
self.__status_code)
|
self.__status_code)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue