rust-prometheus
rust-prometheus copied to clipboard
Provide a way to create auto-unsetting metrics
I'm trying to create components that report metrics through holding an e.g. IntCounter
generated from a registered IntCounterVec
. I would like the set of labels attached to each component to be removed when the component is dropped, to avoid reporting the last value over and over again.
Currently this is very convoluted to achieve, since it requires holding a clone of the MetricVec
, and the inner type of that MetricVec
cannot be specified because it is behind a private submodule of the crate.
What is the best way to achieve this? e.g. to do something in impl Drop
that will remove the set of labels for a counter, but will keep other labels intact?
~~Would exposing MetricVec::reset()
on the gauges help to at least provide manual GC for metric values?~~ Was misreading the code, seems it's already exposed. I suppose you can remove the values manually when you finish a request? Would need a reference to the underlying MetricVec but seems doable? The main issue I foresee is that you probably want a time delay due if you're not pushing metrics for the scraper to pick up the values.