StatsD Handler Mixin

The RequestMetricsMixin mixin will automatically instrument requests by sending statsd increment and timing values as each request finishes.

The default statsd server that is used is localhost:8125. The STATSD_HOST and STATSD_PORT environment variables can be used to set the statsd server connection parameters. Note that the socket for communicating with statsd is created once upon module import and will not change until the application is restarted or the module is reloaded.

In the RequestMetricsMixin, the statsd metrics are prefixed by default with sprockets. To change this value, set the new prefix with the STATSD_PREFIX environment variable.

Each request will send metrics on_finish in the following format:


RequestMetricsMixin Example:

from sprockets.handlers.mixins import statsd
from tornado import web

class MyRequestHandler(stats.RequestMetricsMixin,

    def get(self, *args, **kwargs):
        self.finish({'hello': 'world'})
class sprockets.mixins.statsd.RequestMetricsMixin

Automatically sends statsd metrics upon the completion of each request.

As with all mixins, ensure that you inherit from the mixin classes before you inherit from a concrete class. In addition to this, alway remember to super the on_finish and prepare methods should you decide to extend them.

class MyRequestHandler(
sprockets.mixins.statsd.RequestMetricsMixin, tornado.web.RequestHandler):
def prepare(self):
super(RequestMetricsMixin, self).prepare() do_prepare_stuff()

@gen.coroutine def post(self):


Invoked once the request has been finished. Increments a counter created in the format:


Adds a value to a timer in the following format: