Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

sprockets/sprockets.mixins.statsd

Repository files navigation

sprockets.mixins.statsd

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

Version Downloads Status Coverage License

Deprecation Notice

This project has been replaced by sprockets-statsd and wil no longer be maintained. If you are currently using it, please migrate away from it.

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

https://sprocketsmixinsstatsd.readthedocs.org/

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

About

Handler mixin for automated metric reporting to statsd

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages