Closed ColinBe95 closed 2 months ago
You should be able to just delete registry=multiprocess_registry,
and it will start working, let me know if it doesn't!
When you use multi process mode all of metrics stop using registries in the same way. I do wonder if we should just ignore them or something like that. There could be some very advanced cases where it is useful to still use registries, but it seems more confusing than worthwhile.
Hey @csmarchbanks, thank you so much for the reply. I now have simply:
from prometheus_client import CollectorRegistry, Counter, Summary
from prometheus_client.multiprocess import MultiProcessCollector
multiprocess_registry = CollectorRegistry()
multi_collector = MultiProcessCollector(multiprocess_registry)
CNT_MYMETRIC = Counter(
"cnt_mymetric",
"Counts increment of my metric",
)
i.e. the same code, just without assigning the multiprocess_registry
directly to the Counter and it works.
So if I unerstand your comment correctly, it is enough to set up
multiprocess_registry = CollectorRegistry()
multi_collector = MultiProcessCollector(multiprocess_registry)
and all metrics will automatically use Multiprocess Mode? Assigning the registry=multiprocess_registry,
will duplicate this metric?
I was indeed a little confused here, but I am happy to see it working now :)
Correct. I agree it is confusing. I try to call it out in https://prometheus.github.io/client_python/multiprocess/, but I think some warning from the code would also be nice to have.
I agree that a logged warning could have made sense. Thank you very much! I think we can close this issue :)
Hi everyone, with the upgrade to Prometheus>2.52.0 an error log has been introduced for duplicated samples, i.e.:
A similar issue was raised here, however this issue is not related to the python client.
The metrics in question were all defined like this:
and simply used like:
Now the problem is that we started seeing this error log. However, as I understand Multiprocess metrics, this is expected behaviour. See e.g. docs on Multiprocess Mode:
And I am not sure about what the best way to approach this issue is. One solution I could think of is adding an extra label for the process id, e.g.:
and increase the value by:
But then that would not be a Multiprocess Metric anymore. So I am wondering now if there is a way to use multiprocess metrics with the latest Prometheus version, without getting a ton of these error logs or surpressing them.
Thank you very much!