Hi, this mailing list is for development of Prometheus and related
projects. Since your question is about usage, I'm moving the thread to the
prometheus-users mailing list.

To answer your question, in general a regular expression can have an
unbounded number of matches, so Prometheus cannot automatically determine
from the matcher alone that name2 should be there.

You can set up recording rules with all the names you expect to be there:

- record: probe_success:expected_name
  expr: 1
  labels:
    name: name1
- record: probe_success:expected_name
  expr: 1
  labels:
    name: name2
- record: probe_success:expected_name
  expr: 1
  labels:
    name: name3

and then use it in the your query like

probe_success{name=~"name1|name2|name3"} or -1*probe_success:expected_name

I am using the value 1 for this metric because it is customary to do that
for "metadata metrics" like this – you can multiply it with the desired
value in the query like I did here.

Another thing about your query – you are matching __name__ but that is a
special label representing the metric name. Since your query specifies
probe_success as the metric name, the two are in conflict.

/MR



On Fri, Aug 12, 2022 at 8:35 AM Simon <hadesi1...@gmail.com> wrote:

> Hello everyone,
> I have a query: probe_success{__name__=~"name1|name2|name3"}.
> Prometheus does not have label __name___ = name2 and i want it return -1
> if prometheus does not have that label value.
> How can i do that?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prometheus Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to prometheus-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/prometheus-developers/eccbaad3-9bb0-41a0-a626-25403d34a4d9n%40googlegroups.com
> <https://groups.google.com/d/msgid/prometheus-developers/eccbaad3-9bb0-41a0-a626-25403d34a4d9n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prometheus-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/CAMV%3D_gYuxKbpx62Ve97tvSm0%2Bb15YJcJaE6mkOxiW45jbZcdaw%40mail.gmail.com.

Reply via email to