Grafana query label values

I grafana v8, I want to create a dashboard similar to loki log explorer but with only the labels I am interested in.
For this I need to be able to retreive all values for a given label and put them in a variable dropdown.

It boils down to :
how to initialize a variable with all loki’s values for a given label.

Any hint ?

Hi again @pdelorme,

Just to be sure: have you experimented with the Logs Visualization Panel?

Yes I have. The question is more about building the label dropdown, so I can filter the logs dynamically just like in the log explorer…


Perhaps you could create a query variable for your dashboard, using your Loki datasource.

For the query itself, you could use label_values(label)

As described here, this should return you the list of values for a specific label to select from.


I tried to use the following queries but it doesn’t show anything, there are values of hostname in future, it only takes the values when I recently send the data.


label_values() is only a valid function within templating.

you can’t use it within a dashboard or when querying Prometheus directly.

This topic was automatically closed after 365 days. New replies are no longer allowed.