Avoid duplicated metric types using multiprocess
I'm using the library (v 0.9.0) with multiprocess and I'm getting duplicated metric types. Getting the prometheus metrics I got this:
HELP custom_metric_1 Multiprocess metric
TYPE custom_metric_1 gauge
custom_metric_1 {pid="203"} 1.0 custom_metric_1 {pid="203"} 6.0 ...
HELP custom_metric_1 Multiprocess metric
TYPE custom_metric_1 gauge
custom_metric_1 0.0
My code:
path = os.environ.get("prometheus_multiproc_dir", "/tmp/prometheus") registry = prometheus_client.CollectorRegistry() prometheus_client.multiprocess.MultiProcessCollector(registry, path) metric_1 = prometheus_client.Gauge("custom_metric_1", "", registry=registry)
Any idea for avoiding this duplication.
Hello, I believe the issue here is that you are passing registry=registry to your gauge, and that registry is used by the MultiProcessCollector. I try to call out this scenario in https://github.com/prometheus/client_python#multiprocess-mode-eg-gunicorn, is there something that could make it more clear that in multi process mode one must be careful with registries?