Get the list of a label based on value of another label.

29 views
Skip to first unread message

yagyans...@gmail.com

unread,
Oct 15, 2020, 4:40:28 PM10/15/20
to Prometheus Users
Hi. For every Node Exporter job I have 3 labels - cluster, env and node. Now, I want to extract the label values for the label "node", based on certain conditions.
Value of "node" label for which the "cluster" variable is A + Value of "node" label that start with the string "MDM-" and have "cluster" variable as B.

Is this possible to do?

I want to create these variables in Grafana and I am using label_values to extract the value of label, but I am not able to the above filtering. 

Thanks in advance.

Brian Candler

unread,
Oct 16, 2020, 4:04:04 AM10/16/20
to Prometheus Users
This is really a Grafana question rather than a Prometheus question.

Grafana lets you extract the value of a label from an arbitrary PromQL expression result using a regex, e.g.



The regex is matching against the entire metric line, i.e.

metricname{label1="a",label2="b"} value timestamp

To break the regex down:

.*              match any zero or more characters at start
ifName="        match this text literally (ifName= and opening quote)
(               start capture group
[^"]+           match one or more characters which are not double quote
)               end capture group
"               match literal closing quote
.*              match any zero or more characters at end


Change this to use node instead of ifName.

Then you should be able to write your "or" condition in the PromQL part, e.g.

query_result(foo{cluster="A"} or foo{cluster="B",node=~"MDM-.*"})

yagyans...@gmail.com

unread,
Oct 16, 2020, 6:49:46 AM10/16/20
to Prometheus Users
Wow, Thanks a lot.
Worked like a charm.

Reply all
Reply to author
Forward
0 new messages