Skip to main content

Django Middleware for reporting very simple lightweight timing stats at end of ever page.

Project description

Django Stats Middleware

Django is one of the most popular Python web frameworks today.

When a Django site seems slow, it's nice to put some real number to to that. The Django Debug Toolbar is the go-to middleware solution for diagnosing Django performance among other things, but it is rather large, and slow itself, adding significantly to the load time of your pages. So it's in a bit of catch-22 bind for simple performance overviews.

For that reason I wrote this tiny little lightweight piece of middleware that reports at the bottom of every page a single line reporting some basic timing stats.

  • Total Time: The time from the request arriving to the response being delivered.
  • Python Time: Time spent running Python code
  • DB Time: Time spent waiting on database queries
  • Number of Queries: The number of database queries run

Where:

​ Python Time + DB Time = Total Time

Here's an example:

sample

To use it just put it at the top of your Django Middleware stack:

MIDDLEWARE = (
    'django_stats_middleware.StatsMiddleware',
	...

That way Total Time will include the time spent in all other middleware as well as your site code.

It includes some minimal CSS and to include that in your site include it as an app (so Django knows to collect static files from it):

    INSTALLED_APPS += (
        'django_stats_middleware',
    )

and in your template load the CSS:

    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'django-stats-middleware/css/default.css' %}" />

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

django_stats_middleware-0.3.tar.gz (9.1 kB view hashes)

Uploaded Source

Built Distribution

django_stats_middleware-0.3-py3-none-any.whl (9.9 kB view hashes)

Uploaded Python 3

Supported by

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