Skip to main content

Django InfluxDB Metrics

A reusable Django app that sends metrics about your project to InfluxDB.

Installation

To get the latest stable release from PyPi

pip install django-influxdb-metrics

To get the latest commit from GitHub

pip install -e git+git://github.com/bitmazk/django-influxdb-metrics.git#egg=influxdb_metrix

TODO: Describe further installation steps (edit / remove the examples below):

Add influxdb_metrix to your INSTALLED_APPS

INSTALLED_APPS = (
    ...,
    'influxdb_metrix',
)

Settings

You need to set the following settings:

INFLUXDB_HOST = 'your.influxdbhost.com'
INFLUXDB_PORT = '8086'
INFLUXDB_USER = 'youruser'
INFLUXDB_PASSWORD = 'yourpassword'
INFLUXDB_DATABASE = 'yourdatabase'

# Optional:
INFLUXDB_SERIES_PREFIX = 'yourservername.'
INFLUXDB_SERIES_POSTFIX = '.whatever'

Usage

The app comes with several management commands which you should schedule via crontab.

influxdb_get_memory_usage

Collects the total memory of your user, plus the memory and name of the largest process.

You could schedule it like this:

* * * * * cd /path/to/project/ && /path/to/venv/bin/python /path/to/project/manage.py influxdb_get_memory_usage username > $HOME/mylogs/cron/influxdb-get-memory-usage.log 2>&1

The series created in your influxdb will be named <prefix>server.memory.usage<postfix> and will have the following columns:

  • value: The total memory usage in bytes

  • largest_process: Memory usage of the largest process in bytes

  • largest_process_name: String representing the largest process name

influxdb_get_disk_usage

Collects the total disk usage for the given path.

You could schedule it like this:

* * * * * cd /path/to/project/ && /path/to/venv/bin/python /path/to/project/manage.py influxdb_get_disk_usage $HOME > $HOME/mylogs/cron/influxdb-get-disk-usage.log 2>&1

The series created in your influxdb will be named <prefix>server.disk.usage<postfix> and will have the following columns:

  • value: The total memory usage in bytes

influxdb_get_database_size

Collects the total disk usage for the given database.

You could schedule it like this:

* * * * * cd /path/to/project/ && /path/to/venv/bin/python /path/to/project/manage.py influxdb_get_database_size $HOME > $HOME/mylogs/cron/influxdb-get-database-size.log 2>&1

The series created in your influxdb will be named <prefix>server.postgresql.size<postfix> and will have the following columns:

  • value: The total database size in bytes

InfluxDBEmailBackend

If you would like to track tne number of emails sent, you can set your EMAIL_BACKEND:

EMAIL_BACKEND = 'influxdb_metrics.email.InfluxDBEmailBackend'

The series created in your influxdb will be named <prefix>django.email.sent<postfix> and will have the following columns:

  • value: The number of emails sent

InfluxDBRequestMiddleware

If you would like to track the number and speed of all requests, you can add the InfluxDBRequestMiddleware at the end of your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = [
    ...
    'influxdb_metrics.middleware.InfluxDBRequestMiddleware',
]

The series created in your influxdb will be named <prefix>django.request<postfix> and will have the following columns:

  • value: The request time in milliseconds.

  • is_ajax: 1 if it was an AJAX request, otherwise 0

  • method: The request method (GET or POST)

  • module: The python module that handled the request

  • view: The view class or function that handled the request

  • referer: The full URL from request.META[‘HTTP_REFERER’]

  • referer_tld: The top level domain of the referer. It tries to be smart and

    regards google.co.uk as a top level domain (instead of co.uk)

If you have a highly frequented site, this table could get big really quick. You should make sure to create a shard with a low retention time for this series (i.e. 7d) and add a continuous query to downsample the data into hourly/daily averages. When doing that, you will obviously lose the detailed information like referer and referer_tld but it might make sense to create a second continuous query to count and downsample at least the referer_tld values.

Tracking User Count

This app’s models.py contains a post_save and a post_delete handler which will detect when a user is created or deleted.

The series created in your influxdb will be named <prefix>django.user.count<postfix> and will have the following columns:

  • value: The total number of users in the database

Tracking User Logins

This app’s models.py contains a handler for the user_logged_in signal.

The series created in your influxdb will be named <prefix>django.user.logins<postfix> and will have the following columns:

  • value: 1

Tracking Failed User Logins

This app’s models.py contains a handler for the user_logged_failed signal.

The series created in your influxdb will be named <prefix>django.user.logins.failed<postfix> and will have the following columns:

  • value: 1

Contribute

If you want to contribute to this project, please perform the following steps

# Fork this repository
# Clone your fork
mkvirtualenv -p python2.7 django-influxdb-metrics
make develop

git co -b feature_branch master
# Implement your feature and tests
git add . && git commit
git push -u origin feature_branch
# Send us a pull request for your feature branch

Metadata

Release files for django-influxdb-metrics 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-influxdb-metrics 0.1
File Size Uploaded Provenance Actions
django-influxdb-metrics-0.1.tar.gz 17.3 kB Without provenance Details for django-influxdb-metrics-0.1.tar.gz

Release files / django-influxdb-metrics-0.1.tar.gz

Download URL django-influxdb-metrics-0.1.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
98c0848fdc90d49471bf68ca17ec675c5f52c21995c99c888ef9fcd8ba2cf614
BLAKE2b-256 checksum
How to use checksums
239af8dd8e65e14a2fcace7901911c2cdd153c5546202064ef5137ab282511bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-influxdb-metrics 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page