fralalonde/dipstick

Example of a pull strategy

yterradas opened this issue · 2 comments

hi,

i have been looking through the documentation and examples but i cannot find a way to output the metrics based on a pull strategy. since i am writing a library what i am looking for is a way to iterate over list of metrics exposing their values to the hosting app. is there a way to achieve so?

thank you in advance

Hello! It certainly is possible to do pull metrics. None of the examples show you how but it's a use case that should be covered.

One plan would be to use an AtomicBucket to accumulate stats. Assuming that you want to do answer HTTP requests, the "pull" part would print the bucket's content to the HTTP response using bucket.flush_to(). The specifics will depend on the HTTP lib that you're using. See the bucket example for a rough starting point of this idea.

The plan is to eventually have a Prometheus pull implementation, which you could have based your code upon. If you care to share your code back, I'll be happy to integrate it with the examples.

@fralalonde
thank you for the response.
i am writing a FFI library so i dont have a HTTP response to write to. instead i need to provide a metric_name metric_value (or some other format). the example you provided puts me a little further than i was before in the sense that stats_summary is very close to what i need but i am left with figuring out a SCOPE that will give the metrics on command. i am not knowledgeable enough of Rust to understand what an impl would look like, please educate me if you can.
alternatively the original path i had in mind was looping through each of the metrics, printing out metric_name metric_value. understandably flushing would accomplish the same in a thread-safe way. ultimately i couldnt find a way to get the metric's value so i need some guidance as to how either get the metric's value or to define a scope that gets me data in a string i can pass along.