Git Product home page Git Product logo

django-statsd's Introduction

Introduction

django_statsd is a middleware that uses python-statsd to log query and view durations to statsd.

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:

  1. django_statsd to the INSTALLED_APPS setting.
  2. django_statsd.middleware.StatsdMiddleware to the top of your
    MIDDLEWARE
  3. django_statsd.middleware.StatsdMiddlewareTimer to the bottom of your
    MIDDLEWARE

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's People

Contributors

curlup avatar db48x avatar diogomarques29 avatar dlamotte avatar klen avatar mx14 avatar patoroco avatar plamen-nikolov avatar wolph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-statsd's Issues

Can't install django-statsd 1.9.0

The new 1.9.0 release of django-statsd cannot be installed if python-statsd is not already present:

$ python setup.py install
Traceback (most recent call last):
  File "setup.py", line 7, in <module>
    import django_statsd
  File "/Users/priteau/django-statsd-1.9.0/django_statsd/__init__.py", line 1, in <module>
    from django_statsd.middleware import (
  File "/Users/priteau/django-statsd-1.9.0/django_statsd/middleware.py", line 8, in <module>
    import statsd
ImportError: No module named statsd

This is caused by this import: https://github.com/WoLpH/django-statsd/blob/v1.9.0/setup.py#L7

Settings evaluation on import prevents try/catch inclusion in Django settings

We typically wrap all non-critical components in a try/catch block in Django's settings.py, ie.

STATSD_PREFIX = 'django'
try:
    import django_statsd
    INSTALLED_APPS += (
        'django_statsd',
    )
    MIDDLEWARE = (
        'django_statsd.middleware.StatsdMiddleware',
    ) + MIDDLEWARE + (
        'django_statsd.middleware.StatsdMiddlewareTimer',
    )
except:
    pass

But because django_statsd evaluates its own settings in the import, this happens before the Django-level settings have actually been registered, so it doesn't see any of them (ie. STATSD_PREFIX here doesn't get picked up)

Honestly, this doesn't look fixable without major changes, so I'm planning to work around it. But it seemed worth raising in case I'm wrong about that.

Unable to stop tracking process_response, never started tracking it

When response is returned from middleware, we are getting following error.

STATSD_TRACK_MIDDLEWARE = True
  File "~/.virtualenvs/doconpy/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "~/.virtualenvs/doconpy/lib/python3.6/site-packages/django/utils/deprecation.py", line 142, in __call__
    response = self.process_response(request, response)
  File "~/.virtualenvs/doconpy/lib/python3.6/site-packages/django_statsd/middleware.py", line 198, in process_response
    StatsdMiddleware.scope.timings.stop('process_response')
  File "~/.virtualenvs/doconpy/lib/python3.6/site-packages/django_statsd/middleware.py", line 103, in stop
    'started tracking it' % key)
AssertionError: Unable to stop tracking process_response, never started tracking it

document settings

It would be helpful to document the available settings. Attempting to configure this for the first time and reading through the source code to figure it out but there are a lot of moving pieces. I am not familiar enough with any of this to be of any help but figured I would open the issue

Document/support instrumentation of database

I'm comparing this with the django-statsd-mozilla package. Both work out of the box, but the other better supports SQL and cache timing. On the other hand, your package has a recent pull request and covers json parse/load and rendering time. Have you given any thought to finishing the work in django_statsd.database? Would you be open to a pull request to do so?

Skip some views to send to statsd

Hi,

what do you think about to add a new setting with wildcards for those views that you want to track instead of just to track everything with the middleware?

The use case is avoid to send data about django admin for example.

1.8.0 release on pypi has no setup.py

Can't install this version using pip...

pip install --upgrade django-statsd
Downloading/unpacking django-statsd from http://pypi.python.org/packages/any/d/django-statsd/django-statsd-1.8.0.freebsd-7.2-RELEASE-amd64.tar.gz#md5=44375a6e8b14e7681f77a0bcb675141a
Downloading django-statsd-1.8.0.freebsd-7.2-RELEASE-amd64.tar.gz
Running setup.py egg_info for package django-statsd
Traceback (most recent call last):
File "", line 14, in
IOError: [Errno 2] No such file or directory: '/opt/virtualenvs/arribaa/build/django-statsd/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 14, in

IOError: [Errno 2] No such file or directory: '/opt/virtualenvs/arribaa/build/django-statsd/setup.py'

Add logger client

During development, should be really helpful to have a dummy statsd client that instead of try to send the metrics to the real statsd, it just print logs with the metrics that you're trying to send.

Every 404 error causes regex error from skip_view

We are experiencing an issue with our django app where anytime there is a 404 error, the skip_view function tries to match against a view without a name, and then regex throws an error trying to match against None.

After a little more investigation the view it is trying to compare to is the StatsdMiddleware which has a view_name of None

screenshot_7

    if re.match(pattern, view_name):
  File "/usr/lib/python3.7/re.py", line 173, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object

This is causing a 500 error for every 404.

I'm not sure if we have something misconfigured somewhere or if this is a bug of some kind. Does anyone have any insight or advice about this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.