sprockets.mixins.metrics/README.rst

117 lines
4.2 KiB
ReStructuredText
Raw Normal View History

2016-01-18 20:32:49 +00:00
sprockets.mixins.metrics
========================
2018-07-19 21:23:38 +00:00
|Version| |Status| |Coverage| |License|
2018-12-13 22:26:35 +00:00
Adjust counter and timer metrics in `StatsD`_ using the same API.
2016-01-18 20:32:49 +00:00
2016-01-19 16:43:24 +00:00
The mix-in is configured through the ``tornado.web.Application`` settings
property using a key defined by the specific mix-in.
2021-07-21 17:14:51 +00:00
Deprecation Notice
------------------
This library is deprecated. It will not receive features or bug fixes.
Please switch to either `sprockets-influxdb`_ or `sprockets-statsd`_.
.. _sprockets-influxdb: https://github.com/sprockets/sprockets-influxdb
.. _sprockets-statsd: https://github.com/sprockets/sprockets-statsd
2018-07-19 21:24:53 +00:00
Documentation
-------------
https://sprocketsmixinsmetrics.readthedocs.io
Statsd Mixin
------------
The following snippet configures the StatsD mix-in from common environment
2016-03-10 20:45:50 +00:00
variables. This simple handler will emit a timer metric that identifies each
call to the ``get`` method as well as a separate metric for the database query.
2016-01-19 16:43:24 +00:00
.. code-block:: python
import os
2016-03-10 20:45:50 +00:00
from sprockets.mixins import mediatype
from sprockets.mixins.metrics import statsd
from tornado import web
2016-03-10 20:45:50 +00:00
import queries
2016-01-19 16:43:24 +00:00
def make_application():
2016-07-18 20:49:40 +00:00
application = web.Application([
web.url(r'/', MyHandler),
2016-01-19 16:43:24 +00:00
], **settings)
2016-07-18 20:49:40 +00:00
statsd.install({'namespace': 'my-application',
'host': os.environ.get('STATSD_HOST', '127.0.0.1'),
'port': os.environ.get('STATSD_PORT', '8125')})
return application
2016-03-10 20:45:50 +00:00
class MyHandler(statsd.StatsdMixin,
mediatype.ContentMixin,
web.RequestHandler):
def initialize(self):
super(MyHandler, self).initialize()
self.db = queries.TornadoSession(os.environ['MY_PGSQL_DSN'])
async def get(self, obj_id):
2016-03-10 20:45:50 +00:00
with self.execution_timer('dbquery', 'get'):
result = await self.db.query('SELECT * FROM foo WHERE id=%s',
2016-03-10 20:45:50 +00:00
obj_id)
self.send_response(result)
Settings
^^^^^^^^
:namespace: The namespace for the measurements
:host: The Statsd host
:port: The Statsd port
2016-07-18 20:49:40 +00:00
:prepend_metric_type: Optional flag to prepend bucket path with the StatsD
metric type
2016-01-18 20:32:49 +00:00
Development Quickstart
----------------------
.. code-block:: bash
$ python3.4 -mvenv env
$ . ./env/bin/activate
(env)$ env/bin/pip install -r requires/development.txt
2016-01-19 16:43:24 +00:00
(env)$ nosetests
2016-03-10 20:45:50 +00:00
test_metrics_with_buffer_not_flush (tests.InfluxDbTests) ... ok
test_that_cached_db_connection_is_used (tests.InfluxDbTests) ... ok
test_that_counter_is_tracked (tests.InfluxDbTests) ... ok
test_that_execution_timer_is_tracked (tests.InfluxDbTests) ... ok
test_that_http_method_call_details_are_recorded (tests.InfluxDbTests) ... ok
test_that_metric_tag_is_tracked (tests.InfluxDbTests) ... ok
test_that_add_metric_tag_is_ignored (tests.StatsdMethodTimingTests) ... ok
2016-01-19 16:43:24 +00:00
test_that_cached_socket_is_used (tests.StatsdMethodTimingTests) ... ok
test_that_counter_accepts_increment_value (tests.StatsdMethodTimingTests) ... ok
test_that_counter_increment_defaults_to_one (tests.StatsdMethodTimingTests) ... ok
test_that_default_prefix_is_stored (tests.StatsdMethodTimingTests) ... ok
test_that_execution_timer_records_time_spent (tests.StatsdMethodTimingTests) ... ok
test_that_http_method_call_is_recorded (tests.StatsdMethodTimingTests) ... ok
----------------------------------------------------------------------
2016-03-10 20:45:50 +00:00
Ran 13 tests in 3.572s
2016-01-19 16:43:24 +00:00
OK
(env)$ ./setup.py build_sphinx -q
running build_sphinx
(env)$ open build/sphinx/html/index.html
2016-01-18 20:32:49 +00:00
2016-03-10 20:45:50 +00:00
.. _StatsD: https://github.com/etsy/statsd
2018-07-19 21:23:38 +00:00
.. |Version| image:: https://img.shields.io/pypi/v/sprockets_mixins_metrics.svg
:target: https://pypi.python.org/pypi/sprockets_mixins_metrics
.. |Status| image:: https://img.shields.io/travis/sprockets/sprockets.mixins.metrics.svg
:target: https://travis-ci.org/sprockets/sprockets.mixins.metrics
.. |Coverage| image:: https://img.shields.io/codecov/c/github/sprockets/sprockets.mixins.metrics.svg
:target: https://codecov.io/github/sprockets/sprockets.mixins.metrics?branch=master
.. |License| image:: https://img.shields.io/pypi/l/sprockets_mixins_metrics.svg
:target: https://github.com/sprockets/sprockets.mixins.metrics/blob/master/LICENSE