Skip to main content

Library to monitor your Django 2.0+ app using Satella's metrics

Project description


Build Status Test Coverage Code Climate Issue Count PyPI PyPI version PyPI

django-satella-metrics is a library to measure Django's requests using Satella's metrics

See LICENSE for text of the license. This library may contain code taken from elsewhere on the internets, so this is copyright (c) respective authors.


First, add the following to your MIDDLEWARE (or MIDDLEWARE_CLASSES): 'django_satella_metrics.DjangoSatellaMetricsMiddleware'

Define the following in your settings:

from satella.instrumentation.metrics import getMetric
    'summary_metric': getMetric('django.summary', 'summary'),
    'histogram_metric': getMetric('django.histogram', 'histogram'),
    'status_codes_metric': getMetric('django.status_codes', 'counter')

Or pass any other metrics that you'd like. This is the default configuration, so if you pass nothing it will be as if you passed the listed code.

Extra configuration

If you want URL readed from the request in a different way than reading URL, you can define a key called url_getter. This should contain a callable that accepts a single argument, the request passed, and return a str, the URL to use.

Additionally, if you want the Prometheus exporter to add extra labels to your exported metrics, you can add a key to the config of name extra_labels which will contain a dict with the labels to add, eg.

    'extra_labels': {
        'service_name': 'my_service',
        'instance': 1

If you specify monitor_metrics, which is a bool, to be True, then /metrics endpoint will also be considered during monitoring.

Exporting from the same server

If you want to export metrics to Prometheus using Django, here you go. Just add following rule to your urlpatterns:

from django_satella_metrics import export_metrics

urlpatterns = [
    ... ,
    path('metrics', export_metrics),

External Prometheus server

If you want to set up an external Prometheus server, use the following snippet:

from satella.instrumentation.metrics.exporters import PrometheusHTTPExporterThread
phet = PrometheusHTTPExporterThread('', 8080, {'service_name': 'my_service'})

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-satella-metrics, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size django_satella_metrics-1.1-py2.py3-none-any.whl (4.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size (6.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page