diff --git a/docs/content/multiprocess/_index.md b/docs/content/multiprocess/_index.md index cd129930..f6f0d929 100644 --- a/docs/content/multiprocess/_index.md +++ b/docs/content/multiprocess/_index.md @@ -29,8 +29,26 @@ There's several steps to getting this working: **1. Deployment**: The `PROMETHEUS_MULTIPROC_DIR` environment variable must be set to a directory -that the client library can use for metrics. This directory must be wiped -between process/Gunicorn runs (before startup is recommended). +that the client library can use for metrics. This directory must exist and be +wiped between process/Gunicorn runs, before any metric is created. The +simplest place to do this is the start-up shell script: + +```shell +rm -rf "$PROMETHEUS_MULTIPROC_DIR" +mkdir -p "$PROMETHEUS_MULTIPROC_DIR" +exec gunicorn ... +``` + +Wiping the directory from inside a process that has already defined metrics, +for example in a Celery `worker_init` signal handler, breaks that process's +metrics. A metric without labels creates its value, and with it the process's +`.db` file for that metric type, as soon as the metric is defined, which is +usually at import time. The process keeps writing to that file after it has +been deleted, so every metric of that type in the process silently stops being +reported, including labelled metrics first used after the wipe. Processes +forked after the wipe, such as Gunicorn workers or a Celery prefork pool, open +new files and are not affected; a Celery worker running the `threads` or +`solo` pool is. This environment variable should be set from a start-up shell script, and not directly from Python (otherwise it may not propagate to child processes).