Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/content/multiprocess/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ 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).

## Cleaning `PROMETHEUS_MULTIPROC_DIR`

The multiprocess directory is not cleaned automatically. If it is not wiped before startup, stale files from a previous run can lead to incorrect metrics.

A common pattern is to wipe and recreate the directory in your process manager/entrypoint script **before** starting Gunicorn/workers:

```bash
rm -rf "$PROMETHEUS_MULTIPROC_DIR"
mkdir -p "$PROMETHEUS_MULTIPROC_DIR"
Comment on lines +42 to +43
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rm -rf "$PROMETHEUS_MULTIPROC_DIR"
mkdir -p "$PROMETHEUS_MULTIPROC_DIR"
rm "$PROMETHEUS_MULTIPROC_DIR/*.db"

This might be a bit safer, and one less thing to do. I also wonder if the example should be in python rather than asking people to run bash before starting python?

```

Notes:
- Only wipe a directory that is dedicated to multiprocess metric files.
- In containerized deployments, `PROMETHEUS_MULTIPROC_DIR` is often set to a dedicated path such as `/tmp/prometheus_multiproc_dir`.
- If you run multiple independent apps on the same machine, each should use a separate multiprocess directory.

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).

Expand Down