rust-prometheus icon indicating copy to clipboard operation
rust-prometheus copied to clipboard

How to get a registered Metric

Open jamessewell opened this issue 6 years ago • 4 comments

Hi,

I'm parsing some YAML and making it into Counters and Gauges.

Sometimes some YAML might redefine a metric (name / help / type), which will then be set with different label values. In this case when I add it to the Registry I get prometheus::Error::AlreadyReg - which is fine.

I now need some way of getting the previously made MetricVector and using it with .get_metric_with_label_values().inc() or whatever.

I could keep my own registry beside the Registry - but that seems a bit convoluted. I can see there is some concept of a fqdn - but I can't work out how to get at / use it.

jamessewell avatar Jun 06 '19 05:06 jamessewell

Currently we don't have interfaces to iterate registered metrics. However you can do it indirectly by calling gather()..

breezewish avatar Jun 19 '19 12:06 breezewish

I agree, this would be a very helpful feature.

fredrik-jansson-se avatar Nov 23 '22 11:11 fredrik-jansson-se

We also need this feature as it's not currently possible to get back an already registered collector in a multi-threaded environment (i.e., multiple threads trying to register the same set of metrics and each of them need to get back a handle to increment/decrement the counter). Our code is not ready to use the local-flush feature yet.

Is there any plans to tackle this? If not, I am happy to take a stab at it @lucab @MrCroxx?

trungda avatar Jun 05 '23 05:06 trungda

Anyone still blocked by this; I found that both https://github.com/prometheus/client_rust and https://github.com/metrics-rs/metrics support this fine.

jpds avatar Apr 16 '24 08:04 jpds