Prometheus

How to write a query that returns the value of a label?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

To write a query that returns the value of a label in Prometheus, you can use the label_values function. The label_values function takes two arguments: the name of the label and the name of the metric.

For example, if you have a metric called http_requests_total with a label called method, and you want to return all the values of the method label, you can use the following query:

label_values(http_requests_total, method)

This will return a list of all the values for the method label in the http_requests_total metric. You can then use this list in further queries or to filter your data.