tikv / rust-prometheus

Prometheus instrumentation library for Rust applications
Apache License 2.0
1.07k stars 182 forks source link

How can one create histograms with labels? #417

Closed WaDelma closed 3 years ago

WaDelma commented 3 years ago

I am making a game using ECS pattern with specs. I have 35 systems all in different files. I want to create on histogram for each that tracks how long one tick of execution takes.

If I just create <system name>_system_duration_seconds histograms, it is really hard to create single panel in graphana that would show all of the systems together (You need to do relabeling and subqueries. Or you need to do configuring in prometheus side which I don't really want to delve to). This all would be easier if I could just add label for each system.

There seems to exist HistogramVec, but that is not that great as I would need to copy all system names to one location and then use indices in each system to get their corresponding histogram (or create hash map and use system name) and all of the histograms would share same HistogramOpts which is not necessarily optimal as I might want to tweak bucket sizes depending how heavy system is expected to be.

I guess each system file could add their name to some global hash map that would then used lazily construct the histograms or something.

This all seems horribly complicated when if I just had with_opts_and_label_values exposed or better yet if register_histogram supported giving labels, I could just easily give system name labels. This could even be useful if I wanted to categorize systems based on their function (generic game systems, AI related systems, etc).

WaDelma commented 3 years ago

Ah found now that HistogramOpts actually allows setting label and that register_histogram allow taking that as input... Dunno how I didn't find this earlier :D