Skip to main content

django-satella-metrics

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.

As far as compatible Djangos are considered: This has been tested as early as Django 1.8 with Python 3.6 and as late as Django 3.0.3 with Python 3.8. Enjoy!

Usage

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
DJANGO_SATELLA_METRICS = {
    '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.

DJANGO_SATELLA_METRICS = {
    'extra_labels': {
        'service_name': 'my_service',
        'instance': 1
    },
    'monitor_metrics': False
}

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('0.0.0.0', 8080, {'service_name': 'my_service'})
phet.start()

Release files for django-satella-metrics 1.6

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

Built distribution (wheel)

Table of built distributions (wheels) for django-satella-metrics 1.6
File Interpreter ABI Platform
django_satella_metrics-1.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / django_satella_metrics-1.6-py2.py3-none-any.whl

Download URL django_satella_metrics-1.6-py2.py3-none-any.whl
Size 5.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
55ec4d8e6298c4daeb8b0eb31bb4fc65d6be224e1d3d01eecdef6797aadbc0af
BLAKE2b-256 checksum
How to use checksums
8dc1022b12337c68764f10467c240a457984e317b9c00754775bbd72be0f01e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

Release history Release notifications | RSS feed

This release

1.6 This release

1 release file

1.5

2 release files

1.4

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

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