Handler mixins for automated metric reporting
Project description
The RequestMetricsMixin mixin will automatically instrument requests by sending statsd increment and timing values as each request finishes.
Installation
sprockets.mixins.statsd is available on the Python Package Index and can be installed via pip or easy_install:
pip install sprockets.mixins.statsd
Documentation
Requirements
Example
The following RequestHandler will automatically increment a request counter and add a request duration timing value to statsd when the request finishes.
from sprockets.mixins import statsd
from tornado import web
class MyRequestHandler(statsd.RequestMetricsMixin,
web.RequestHandler):
def prepare(self):
self.statsd_prefix = 'some.overriden.value'
super(MyRequestHandler, self).prepare()
def get(self, *args, **kwargs):
self.finish({'hello': 'world'})
def on_finish(self):
super(MyRequestHandler, self).on_finish()
self.do_cleanup_things()
When the request has finished, the following keys would be used:
Counter: sprockets.counter.example.RequestHandler.GET.200
Timing: sprockets.timers.example.RequestHandler.GET.200
Mixin Behavior
Whenever you mix in a class in Python always ensure that the mixins, which should inherit from object, are the first ones in the inheritance list. The concrete class, in this case web.RequestHandler should be the final class inherited.
Should your Request Handler extend the finish or the prepare methods ensure that your call super otherwise you may run into strange behavior.
Version History
Available at https://sprocketsmixinsstatsd.readthedocs.org/en/latest/history.html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sprockets.mixins.statsd-1.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb6f5ee3e9e8899dce13e543c392f2ae6f535ffad418ba3493624a5bfdd22c7 |
|
MD5 | b1a5ad8fa3eed8082c5c90639a8cfffc |
|
BLAKE2b-256 | 571962cf700b3c3ef49586d0e2f98c45299826a55176a11362f6f795aa692879 |
Hashes for sprockets.mixins.statsd-1.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed7a855438fd74419ff06fc74cc34fa407bd49d5b44e821646bd9b8b79c33b69 |
|
MD5 | 6b51d868d2b37ac0f71be66b21a35a35 |
|
BLAKE2b-256 | e086f07caf9d79bc2e0feb4d5a6e35edf7f237c0e3d7d9e3f9a8eb71220ca1bd |