Using another metric for the legend of a panel

Hey,

I create a dashboard to visualize the performance of my games. Therefore I wrote my own prometheus exporter that looks like this:

# HELP views_count_total Views count
# TYPE views_count_total counter
views_count_total{game_id="1"} 223.0
views_count_total{game_id="2"} 646.0
# HELP downloads_count_total Downloads count
# TYPE downloads_count_total counter
downloads_count_total{game_id="1"} 6.0
downloads_count_total{game_id="2"} 190.0
# HELP purchases_count_total Purchases count
# TYPE purchases_count_total counter
purchases_count_total{game_id="1"} 0.0
purchases_count_total{game_id="2"} 0.0
# HELP meta_info Meta information
# TYPE meta_info gauge
meta_info{created="1720000000000",description="My first game",game_id="1",published="1721000000000",title="First Game"} 1.0
meta_info{created="1730000000000",description="My second game",game_id="2",published="1731000000000",title="Second Game"} 1.0

In my dashboard I try to create a panel that visualize the download of all games in one graph.
So far I defined game_id as a variable in the dashboard settings. And in the panel I simply use views_count_total.
As expected the I see the time series for the games with id “1” and “2”. The legend also shows this ids. I would like to transform the legend to the human-readable values “First Game” and “Second Game” by using the meta_info.

So far I tried some Transforms like “Join” or “Merge”, but I find nothing that looks promising. I also read about the replace_label function, but I find also nothing that seems to work.
Also changing the label from game_id to title in the exporter would not be optimal, cause the titles can - in theory - change.

Is there something I am missing?

Remarks:

  • I use Grafana v11.1.3 (beac3bdbcb)
  • I can change the metrics of the prometheus exporter

Typical solution is to use join on the PromQL level. Random blog post how to do that:

Thanks, views_count_total * on(game_id) group_left(title) meta_info{} did the trick!

1 Like