Closed vojtechkral closed 3 months ago
There is no way to insert a metric into Registry
from an existing handle type (e.g. Counter
), unfortunately.
You could potentially write a custom wrapper type that holds a Counter
(or Gauge
), etc, and an Arc<...>
to your own data, and then implement the appropriate handle trait -- CounterFn
, etc -- to call the same method on the underlying Counter
as well as updating your Arc<...>
.
Ok. At the moment I just keep a second Arc<AtomicX>
next to my Gauge
.
It occurred to me the method may have been meant for tests for injecting counters/gauges without an actual recorder?
There's no reason those helper methods couldn't be used for testing, this is true... but it wasn't the primary reason to add them.
Going to close this since it seems like the issue was resolved.
Hi,
The
Gauge
andCounter
types can be created with afrom_arc()
method. This seems useful, I have some state in my application that I'd like to share around in anArc<AtomicU64>
and use for logic, at the same time I need the number reported in metrics.But I don't know what to do with a
Gauge
value once created - it doesn't seem to be possible to register it into aRecorder
.Can this be done? Thanks!