django-prometheus is a Python library that provides Prometheus metrics for Django applications. It offers automatic instrumentation for HTTP requests, database queries, and cache operations, as well as features for exposing custom application-level metrics. The library is actively maintained, with version 2.4.1 being the latest release, and regularly updates to support new Django and Python versions.
pip install django-prometheusVerified import paths — ran on the pinned version, not inferred.
To quickly integrate django-prometheus, add 'django_prometheus' to your `INSTALLED_APPS`. Then, include `PrometheusBeforeMiddleware` and `PrometheusAfterMiddleware` in your `MIDDLEWARE` list, ensuring they wrap other core Django middlewares. Finally, include `django_prometheus.urls` in your project's `urls.py` to expose the metrics endpoint (typically at `/metrics/`).
Upgrade your Django and Python versions to supported ones (Django >= 4.2, Python >= 3.9 for 2.4.1) before upgrading django-prometheus.
Ensure your project runs on Python 3.7+ and Django 3.2+ before upgrading to django-prometheus 2.3.0 or newer.
Always follow the recommended order: `PrometheusBeforeMiddleware` at the start, `PrometheusAfterMiddleware` at the end, with other middlewares in between. Consult the official documentation for the exact order.
Set `PROMETHEUS_EXPORT_MIGRATIONS = True` in your `settings.py` if you wish to continue monitoring Django migrations.
Upgrade to django-prometheus version 2.3.0 or newer to ensure all latency metrics consistently respect the `PROMETHEUS_LATENCY_BUCKETS` setting.