metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.08k stars 148 forks source link

Instant available metrics #442

Open 0xdeafbeef opened 7 months ago

0xdeafbeef commented 7 months ago

I've encountered a scenario where certain metrics, such as allocation statistics/collections length are instantly available but are external and not directly controllable. Currently, the approach to forward these metrics to metrics is by employing tokio::spawn with an endless loop as shown below:

tokio::spawn(async {
    loop {
        let data = get_value();
        metrics::gauge("measurement").set(data);
        tokio::time::sleep(Duration::from_secs(5));
    }
});

While this method works, it's not the most efficient or elegant solution, particularly when considering that exporters may have varying scrape intervals.

Suggestion:

Would it be possible to introduce a global notification mechanism, on which all metrics will render their measurements?

tobz commented 6 months ago

It would likely be possible to support, yes.

We used to have support for this -- we called them proxies -- but they were removed as the crate evolved and we started to simplify the interface more and more.

I have thoughts on how I would want to see this approached if developed, but I don't have the time to work on this and it would be a lower priority than many other outstanding bugs/missing features. If you (or anyone else) would be interested in working on this, though, I would be willing to try and guide you on the work.