Django Statsd Client¶
Contents:
Introduction¶
django_statsd is a middleware that uses python-statsd to log query and view durations to statsd.
- Documentation
- Bug reports
- Package homepage
- Python Statsd
- Graphite
Install¶
To install simply execute python setup.py install. If you want to run the tests first, run python setup.py test
Usage¶
To install, add the following to your settings.py
:
django_statsd
to theINSTALLED_APPS
setting.django_statsd.middleware.StatsdMiddleware
to the top of yourMIDDLEWARE
django_statsd.middleware.StatsdMiddlewareTimer
to the bottom of yourMIDDLEWARE
Configuration¶
You can configure django-statsd
using the Django settings config:
>>> # Settings
... STATSD_HOST = '127.0.0.1'
... STATSD_PORT = 12345
The full list of configurations is available in ReadTheDocs.
Advanced Usage¶
>>> def some_view(request):
... with request.timings('something_to_time'):
... # do something here
... pass
>>>
>>> def some_view(request):
... request.timings.start('something_to_time')
... # do something here
... request.timings.stop('something_to_time')
django_statsd Package¶
django_statsd
Package¶
settings
Module¶
-
django_statsd.settings.
STATSD_DEBUG
= True¶ Enable warnings such as timers which are started but not finished. Defaults to DEBUG if not configured
-
django_statsd.settings.
STATSD_DISABLED
= False¶ Statsd disabled mode, avoids to send metrics to the real server. Useful for debugging purposes.
-
django_statsd.settings.
STATSD_HOST
= '127.0.0.1'¶ Statsd host, defaults to 127.0.0.1
-
django_statsd.settings.
STATSD_PORT
= '8125'¶ Statsd port, defaults to 8125
-
django_statsd.settings.
STATSD_PREFIX
= 'some_key_prefix'¶ Set the global statsd prefix if needed. Otherwise use the root
-
django_statsd.settings.
STATSD_SAMPLE_RATE
= 1.0¶ Statsd sample rate, lowering this decreases the (random) odds of actually submitting the data. Between 0 and 1 where 1 means always
-
django_statsd.settings.
STATSD_TAGS_LIKE
= None¶ Enable creating tags as well as the bare version. This causes an ajax view to be stored both as the regular view name and as the ajax tag. Supported separators are _is_ and =
-
django_statsd.settings.
STATSD_TRACK_MIDDLEWARE
= True¶ Enable tracking all requests using the middleware
-
django_statsd.settings.
STATSD_VIEWS_TO_SKIP
= ['django.contrib.admin']¶ List of regexp to ignore views.
celery
Module¶
database
Module¶
middleware
Module¶
-
class
django_statsd.middleware.
Client
(prefix='view')[source]¶ Bases:
object
-
class_
¶ alias of
statsd.client.Client
-
-
class
django_statsd.middleware.
Counter
(prefix='view')[source]¶ Bases:
django_statsd.middleware.Client
-
class_
¶ alias of
statsd.counter.Counter
-
-
class
django_statsd.middleware.
StatsdMiddleware
(get_response=None)[source]¶ Bases:
django.utils.deprecation.MiddlewareMixin
-
scope
= <thread._local object>¶
-
-
class
django_statsd.middleware.
Timer
(prefix='view')[source]¶ Bases:
django_statsd.middleware.Client
-
class_
¶ alias of
statsd.timer.Timer
-