django-site-metrics

django-site-metrics is a statistics module for django. It stores requests in a database for admins to see, it can also be used to get statistics on who is online etc.

https://bitbucket.org/rsalmaso/django-site-metrics/raw/default/docs/graph.png

As well as a site statistics module, with the active_users template tag and manager method you can also use django-site-metrics to show who is online in a certain time.

django-site-metrics is a “fork” of django-request, which focus only on postgresql support and is able to use a separate database.

First steps

Quick start guide

Note

To find the request overview page, please click on Requests inside the admin, then “Overview” on the top right, next to “add request”.

Once you have installed django-site-metrics you can add it to a django project by following these steps;

  1. Install the blog app by adding 'metrics' to INSTALLED_APPS.
  2. Run manage.py migrate so that Django will create the database tables.
  3. Add metrics.middleware.RequestMiddleware to MIDDLEWARE. If you use django.contrib.auth.middleware.AuthenticationMiddleware, place RequestMiddleware after it. If you use django.contrib.flatpages.middleware.FlatpageFallbackMiddleware place metrics.middleware.RequestMiddleware before it else flatpages will be marked as error pages in the admin panel.
  4. Make sure that the domain name in django.contrib.sites admin is correct. This is used to calculate unique visitors and top referrers.

django-admin.py

purgerequests

This command can be used to purge old requests, it takes two arguments amount and duration. Example:

$ python manage.py purgerequests 1 month
$ python manage.py purgerequests 2 weeks

It also has a option called --noinput, if this is supplied, it will not ask you to confirm. With this option you can use this command in a cron.

Valid durations: hour(s), day(s), week(s), month(s), year(s)