Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if label value is in the list of possible values for prometheus

I want to check if value for the metric is above threshold for a metric with a specific values in a label. I have a long list of those values (~30), and only those.

a_metric_total {alabel="foo"} >= 1

alabel can be foo, foobar, bar, (but not barfoo, so I don’t want to use regexp).

I wanted something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a_metric_total {alabel in ["foo", "bar", "foobar"]} >= 1

Is there a way to do in operation for a label and a set/list of constants?

>Solution :

Correct way to select metrics based on multiple values of label are regex.

So for your example this query will return what you describe:

a_metric_total{alabel=~"foo|bar|foobar"} >= 1

Please note, that regex selectors for labels are fully anchored (so selector in example is equivalent to ^(foo|bar|foobar)$) and thus no partial matching is occurring. For regex selector in promql to partially match you need to manually specify that: .*foo.*|.*bar.* will match any label containing "foo" or "bar", but foo|bar matches only "foo" or "bar", but not "foobar".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading