sprockets.mixins.metrics
Adjust counter and timer metrics in StatsD using the same API.
The mix-in is configured through the tornado.web.Application settings property using a key defined by the specific mix-in.
Documentation
Statsd Mixin
The following snippet configures the StatsD mix-in from common environment 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.
import os
from sprockets.mixins import mediatype
from sprockets.mixins.metrics import statsd
from tornado import web
import queries
def make_application():
application = web.Application([
web.url(r'/', MyHandler),
], **settings)
statsd.install({'namespace': 'my-application',
'host': os.environ.get('STATSD_HOST', '127.0.0.1'),
'port': os.environ.get('STATSD_PORT', '8125')})
return application
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):
with self.execution_timer('dbquery', 'get'):
result = await self.db.query('SELECT * FROM foo WHERE id=%s',
obj_id)
self.send_response(result)
Settings
- namespace:
The namespace for the measurements
- host:
The Statsd host
- port:
The Statsd port
- prepend_metric_type:
Optional flag to prepend bucket path with the StatsD metric type
Development Quickstart
$ python3.4 -mvenv env
$ . ./env/bin/activate
(env)$ env/bin/pip install -r requires/development.txt
(env)$ nosetests
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
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
----------------------------------------------------------------------
Ran 13 tests in 3.572s
OK
(env)$ ./setup.py build_sphinx -q
running build_sphinx
(env)$ open build/sphinx/html/index.html
Metadata
Release files for sprockets.mixins.metrics 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sprockets.mixins.metrics-4.1.0.tar.gz | 16.4 kB | Without provenance | Details for sprockets.mixins.metrics-4.1.0.tar.gz |
Release files / sprockets.mixins.metrics-4.1.0.tar.gz
| Download URL | sprockets.mixins.metrics-4.1.0.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e1a90f846fafb06f951b62bf7e398820bc7164235b71e1acae6deba7445bbae
|
|
BLAKE2b-256 checksum How to use checksums |
09e556f8e744eff8557d07029f438de113fdeeb15852a0db3114a772f5e6d0aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1
|
Security for sprockets.mixins.metrics 4.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.