client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Avoid duplicated metric types using multiprocess

Open alexcanar95 opened this issue 4 years ago • 1 comments

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.

alexcanar95 avatar Jul 20 '21 07:07 alexcanar95

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?

csmarchbanks avatar Jul 20 '21 16:07 csmarchbanks