Prometheus templating using label_values - dynamic row and panel repeat

Let’s imagine I have a metric called calories and two labels called type and name. type says whether we have fruit or vegetable, name is a name of the fruit or vegetable e.g. carrot, onion, banana, orange, apple. What I would like to do is to create a single stat panel that would be repeated in rows in the following way (of course - refreshed dynamically on dashboard load):
row 1: vegetables with panels for carrot and onion
row 2: fruits with panels for banana, orange, apple

My attempt so far is two vars on the dashboard level:
$types = label_values(type)
$names = label_values(calories{type=~"$types"}, name)

and I am repeating rows for types and repeating panels for names however unfortunately I am getting all the names (both fruits and veggies) in both rows.

First of all - is this achievable what I am trying to do?
If so - what am I doing wrong?


Has anyone got any idea whether this is doable? A quick answer like “no way in Grafana and Prometheus” would be also helpful. Thanks!

Hi @michalrudko, I don’t think this is currently possible. There is a feature request at github for hiding empty panels/panels with no data, that would solve your issue.

1 Like