2016-01-19 12:51:09 +00:00
|
|
|
Reference Documentation
|
|
|
|
=======================
|
|
|
|
This library defines mix-ins that record application metrics. Each mix-in
|
|
|
|
implements the same interface:
|
|
|
|
|
|
|
|
.. class:: sprockets.mixins.metrics.Mixin
|
|
|
|
|
|
|
|
.. data:: SETTINGS_KEY
|
|
|
|
|
|
|
|
Key in ``self.application.settings`` that contains this particular
|
|
|
|
mix-in's configuration data.
|
|
|
|
|
2016-01-19 16:14:02 +00:00
|
|
|
.. method:: record_timing(duration, *path)
|
2016-01-19 15:43:02 +00:00
|
|
|
:noindex:
|
2016-01-19 12:51:09 +00:00
|
|
|
|
2016-01-19 16:14:02 +00:00
|
|
|
:param float duration: number of seconds to record
|
2016-01-19 15:43:02 +00:00
|
|
|
:param path: timing path to record
|
|
|
|
|
2016-01-19 16:14:02 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
self.record_timing(self.request.request_time(), 'request', 'lookup')
|
|
|
|
|
2016-01-19 15:43:02 +00:00
|
|
|
.. method:: increase_counter(*path, amount=1)
|
2016-01-27 15:46:23 +00:00
|
|
|
:noindex:
|
2016-01-19 15:43:02 +00:00
|
|
|
|
|
|
|
:param path: counter path to increment
|
|
|
|
:keyword int amount: value to increase the counter by
|
2016-01-19 12:51:09 +00:00
|
|
|
|
2016-01-19 16:14:02 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
self.increase_counter('db', 'query', 'foo')
|
|
|
|
|
|
|
|
.. method:: execution_timer(*path)
|
2016-01-27 15:46:23 +00:00
|
|
|
:noindex:
|
2016-01-19 16:14:02 +00:00
|
|
|
|
|
|
|
: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')
|
|
|
|
|
2016-01-27 15:46:23 +00:00
|
|
|
.. method:: set_metric_tag(tag, value)
|
|
|
|
:noindex:
|
|
|
|
|
|
|
|
:param str tag: the tag to set
|
|
|
|
:param str value: the value to assign to the tag
|
|
|
|
|
|
|
|
This method stores a tag and value pair to be reported with
|
|
|
|
metrics. It is only implemented on back-ends that support
|
|
|
|
tagging metrics (e.g., :class:`sprockets.mixins.metrics.InfluxDBMixin`)
|
|
|
|
|
2016-01-19 12:51:09 +00:00
|
|
|
|
|
|
|
Statsd Implementation
|
|
|
|
---------------------
|
|
|
|
.. autoclass:: sprockets.mixins.metrics.StatsdMixin
|
|
|
|
:members:
|
2016-01-19 13:55:51 +00:00
|
|
|
|
2016-01-21 20:49:35 +00:00
|
|
|
InfluxDB Implementation
|
|
|
|
-----------------------
|
|
|
|
.. autoclass:: sprockets.mixins.metrics.InfluxDBMixin
|
|
|
|
:members:
|
|
|
|
|
|
|
|
.. autoclass:: sprockets.mixins.metrics.influxdb.InfluxDBConnection
|
|
|
|
:members:
|
|
|
|
|
2016-01-19 13:55:51 +00:00
|
|
|
Testing Helpers
|
|
|
|
---------------
|
|
|
|
*So who actually tests that their metrics are emitted as they expect?*
|
|
|
|
|
|
|
|
Usually the answer is *no one*. Why is that? The ``testing`` module
|
|
|
|
contains some helper that make testing a little easier.
|
|
|
|
|
|
|
|
.. autoclass:: sprockets.mixins.metrics.testing.FakeStatsdServer
|
|
|
|
:members:
|
2016-01-21 19:49:11 +00:00
|
|
|
|
|
|
|
.. autoclass:: sprockets.mixins.metrics.testing.FakeInfluxHandler
|
|
|
|
:members:
|