8000 Document passing a multiprocess registry to start_http_server. · ioggstream/client_python@2dffcbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 2dffcbc

Browse files
committed
Document passing a multiprocess registry to start_http_server.
1 parent 397eec5 commit 2dffcbc

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ implement a proper `describe`, or if that's not practical have `describe`
403403
return an empty list.
404404

405405

406-
## Multiprocess Mode (Gunicorn)
406+
## Multiprocess Mode
407407

408408
Prometheus client libaries presume a threaded model, where metrics are shared
409409
across workers. This doesn't work so well for languages such as Python where
@@ -417,6 +417,28 @@ This comes with a number of limitations:
417417
- The pushgateway cannot be used
418418
- Gauges cannot use the `pid` label
419419

420+
Create a multiprocess registry and expose it via `start_http_server`.
421+
422+
```python
423+
424+
from prometheus_client import multiprocess, CollectorRegistry
425+
426+
mpr = CollectorRegistry()
427+
multiprocess.MultiProcessCollector(mpr)
428+
429+
...
430+
431+
# Serve multiprocess metrics
432+
start_http_server(8001, registry=mpr)
433+
434+
# Serve default registry.
435+
start_http_server(8000)
436+
437+
```
438+
439+
440+
## Multiprocess Mode (Gunicorn)
441+
420442
There's several steps to getting this working:
421443

422444
**One**: Gunicorn deployment

0 commit comments

Comments
 (0)
0