8000
We read every piece of feedback, and take your input very seriously.
1 parent 9a6e21d commit 6d572dfCopy full SHA for 6d572df
README.md
@@ -494,7 +494,7 @@ implement a proper `describe`, or if that's not practical have `describe`
494
return an empty list.
495
496
497
-## Multiprocess Mode (Gunicorn)
+## Multiprocess Mode (E.g. Gunicorn)
498
499
Prometheus client libraries presume a threaded model, where metrics are shared
500
across workers. This doesn't work so well for languages such as Python where
@@ -504,30 +504,38 @@ To handle this the client library can be put in multiprocess mode.
504
This comes with a number of limitations:
505
506
- Registries can not be used as normal, all instantiated metrics are exported
507
+ - Registering metrics to a registry later used by a `MultiProcessCollector`
508
+ may cause duplicate metrics to be exported
509
- Custom collectors do not work (e.g. cpu and memory metrics)
510
- Info and Enum metrics do not work
511
- The pushgateway cannot be used
512
- Gauges cannot use the `pid` label
513
514
There's several steps to getting this working:
515
-**1. Gunicorn deployment**:
516
+**1. Deployment**:
517
518
The `prometheus_multiproc_dir` environment variable must be set to a directory
519
that the client library can use for metrics. This directory must be wiped
-between Gunicorn runs (before startup is recommended).
520
+between process/Gunicorn runs (before startup is recommended).
521
522
This environment variable should be set from a start-up shell script,
523
and not directly from Python (otherwise it may not propagate to child processes).
524
525
**2. Metrics collector**:
526
-The application must initialize a new `CollectorRegistry`,
-and store the multi-process collector inside.
527
+The application must initialize a new `CollectorRegistry`, and store the
528
+multi-process collector inside. It is a best practice to create this registry
529
+inside the context of a request to avoid metrics registering themselves to a
530
+collector used by a `MultiProcessCollector`. If a registry with metrics
531
+registered is used by a `MultiProcessCollector` duplicate metrics may be
532
+exported, one for multiprocess, and one for the process serving the request.
533
534
```python
535
from prometheus_client import multiprocess
-from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST
536
+from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST, Counter
537
+
538
+MY_COUNTER = Counter('my_counter', 'Description of my counter')
539
540
# Expose metrics.
541
def app(environ, start_response):