Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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.


sprockets.mixins.statsd is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.mixins.statsd


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,

    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()

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.

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
sprockets.mixins.statsd-1.3.1-py2.py3-none-any.whl (8.6 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Jun 26, 2015
sprockets.mixins.statsd-1.3.1.tar.gz (5.0 kB) Copy SHA256 Checksum SHA256 Source Jun 26, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting