Skip to content

Commit

Permalink
Add support for uppercase PROMETHEUS_MULTIPROC_DIR (#276)
Browse files Browse the repository at this point in the history
The variable name prometheus_multiproc_dir was deprecated in django-prometheus 0.10.0 in favor of PROMETHEUS_MULTIPROC_DIR.
  • Loading branch information
otraczyk authored Nov 15, 2021
1 parent 48a758f commit 97d5748
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion django_prometheus/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def ExportToDjangoView(request):
You can use django_prometheus.urls to map /metrics to this view.
"""
if "prometheus_multiproc_dir" in os.environ:
if ("PROMETHEUS_MULTIPROC_DIR" in os.environ
or "prometheus_multiproc_dir" in os.environ):
registry = prometheus_client.CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
else:
Expand Down
8 changes: 4 additions & 4 deletions documentation/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ targets as you have workers, using each port separately.

This approach requires the application to be loaded into each child process.
uWSGI and Gunicorn typically load the application into the master process before forking the child processes.
Set the [lazy-apps option](https://uwsgi-docs.readthedocs.io/en/latest/Options.html#lazy-apps) to `true` (uWSGI)
Set the [lazy-apps option](https://uwsgi-docs.readthedocs.io/en/latest/Options.html#lazy-apps) to `true` (uWSGI)
or the [preload-app option](https://docs.gunicorn.org/en/stable/settings.html#preload-app) to `false` (Gunicorn)
to change this behaviour.
to change this behaviour.


## Exporting /metrics in a WSGI application with multiple processes globally

In some WSGI applications, workers are short lived (less than a minute), so some
are never scraped by prometheus by default. Prometheus client already provides
a nice system to aggregate them using the env variable: `prometheus_multiproc_dir`
a nice system to aggregate them using the env variable: `PROMETHEUS_MULTIPROC_DIR`
which will configure the directory where metrics will be stored as files per process.

Configuration in uwsgi would look like:

```ini
env = prometheus_multiproc_dir=/path/to/django_metrics
env = PROMETHEUS_MULTIPROC_DIR=/path/to/django_metrics
```

You can also set this environment variable elsewhere such as in a kubernetes manifest.
Expand Down

0 comments on commit 97d5748

Please sign in to comment.