Skip to main content

WSGI middleware for statsd timing

Project description

wsgi-statsd documentation

https://api.travis-ci.org/paylogic/wsgi-statsd.png https://pypip.in/v/wsgi-statsd/badge.png https://coveralls.io/repos/paylogic/wsgi-statsd/badge.svg?branch=master

wsgi_statsd is a WSGI middleware that provides an easy way to time all requests. Integration is as easy as just wrapping your existing wsgi application.

Usage

In your wsgi.py file wrap your WSGI application as follows:

import statsd
from wsgi_statsd import StatsdTimingMiddleware


def application(environ, start_response):
    response_body = 'The request method was %s' % environ['REQUEST_METHOD']
    status = '200 OK'
    response_headers = [('Content-Type', 'text/plain'),
                        ('Content-Length', str(len(response_body)))]

    start_response(status, response_headers)

    return [response_body]

client = statsd.StatsClient(
    prefix='your_prefix',
    host='your_host',
    port=8125
)

application = StatsdTimingMiddleware(application, client)

What it does

The middleware uses the statsd timer function, using the environ[‘PATH_INFO’], environ[‘REQUEST_METHOD’] and the status code variables as the name for the key and the amount of time the request took as the value.

That’s it.

If you want more granular reporting you’ll have to work with the prefix argument. You can pass any string you want and the middleware will pass it along to statsd.

Using the foo prefix and calling the www.spam.com/bar page will result in foo.bar.GET.200 having a value equal to the time it took to handle the request.

Contact

If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.

License

This software is licensed under the MIT license

Please refer to the license file

© 2015 Wouter Lansu, Paylogic International and others.

Changelog

0.2.0

  • Fixed version numbers

  • Added support for WSGI applications returning generators

  • Added a test to verify that the response body remains the same after passing through the middleware

0.1.0

  • Initial public release

Project details


Download files

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

Source Distribution

wsgi-statsd-0.2.0.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file wsgi-statsd-0.2.0.tar.gz.

File metadata

  • Download URL: wsgi-statsd-0.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wsgi-statsd-0.2.0.tar.gz
Algorithm Hash digest
SHA256 932602c0e080e89cee1dbec0f5db959ab5059245b5cee6c55cac4938212086cf
MD5 c35ee8d050726ba70e9bb79cc2ec0130
BLAKE2b-256 c3e299144c3d84a1043f69e33157cb4ac9b4885886e922b2e23746c0018f585b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page