Can I use lists in Prometheus / Prometheues in Grafana?

Viewed 221

I am selecting a source / device via up{instance='$mac'} in Grafana from a Prometheus data source. The Grafana variable $mac is a string representing the host name etc. which I generate depending on the user input from a (Postgre)SQL database. This works. Now I want to do 2 things:

  1. Use a self set label (e.g. the location of the device instead of its mac address)
  2. Use a list / array of mac addresses for instance as well another variable for the labels in the legend.

The vectors mentioned on https://prometheus.io/docs/prometheus/latest/querying/basics/ seems to be for the time values only. Basically I am searching something equivalent to IN in SQL.

1 Answers

If I understood you correctly you are trying to retrieve from a given metric up some array of values. This is what you do some analogy with IN operator in SQL. From the docs you can use =~: Select labels that regex-match the provided string. For instance, the query below uses it here.

up{job=~"(prometheus|alertmanager)"}

or you can use the analog of NOT IN: !~: Select labels that do not regex-match the provided string.

up{job!~"(prometheus)"}

Then I think you can replace the values with your $mac variables on Grafana.

Related