Select metric only if another does not exist

43 views
Skip to first unread message

Seitan

unread,
Aug 4, 2020, 3:30:05 AM8/4/20
to Prometheus Users
Hello,
I'm trying to do a promql query to select only hosts, that don't have specific label on them.
For example, selecting metrics from hosts who DO have label (type=value) works:

metrics_name * on (hostname) another_metrics{type="value"}

Problem is when i try to do same select against hosts without that label:


metrics_name * on (hostname) (absent(another_metrics{type="value"}))

this query gives no results.
Is there any way to do such query?
Thank you


Brian Candler

unread,
Aug 4, 2020, 4:35:00 AM8/4/20
to Prometheus Users
On Tuesday, 4 August 2020 08:30:05 UTC+1, Seitan wrote:
I'm trying to do a promql query to select only hosts, that don't have specific label on them.

The empty value is equivalent to "no label":

metric{type=""}

will select timeseries 'metric' which have no label 'type'.

Seitan

unread,
Aug 4, 2020, 4:48:05 AM8/4/20
to Prometheus Users
Hello,
the problem is that the node has label with many values:

metric{type="one"},
metric{type="two"},
metric{type="three"}

I just need do query against those nodes, who has no
metric{type="two"}
Message has been deleted

Sam Lee

unread,
Aug 4, 2020, 7:44:30 AM8/4/20
to Prometheus Users
try metric{type != "two"} ?

在 2020年8月4日星期二 UTC+8下午3:30:05,Seitan写道:

Aliaksandr Valialkin

unread,
Aug 4, 2020, 10:57:30 AM8/4/20
to Sam Lee, Prometheus Users
Try the following query:

metric_name unless on (hostname) another_metrics{type="value"}

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/bce85d3d-80c0-4ffb-ae40-9b0476a5b553o%40googlegroups.com.


--
Best Regards,

Aliaksandr Valialkin, CTO VictoriaMetrics

Seitan

unread,
Aug 4, 2020, 11:33:38 AM8/4/20
to Prometheus Users
Seems to work correctly.
Thank you very much!

On Tuesday, August 4, 2020 at 5:57:30 PM UTC+3, Aliaksandr Valialkin wrote:
Try the following query:

metric_name unless on (hostname) another_metrics{type="value"}

On Tue, Aug 4, 2020 at 2:44 PM Sam Lee <lixq...@gmail.com> wrote:
try metric{type != "two"} ?

在 2020年8月4日星期二 UTC+8下午3:30:05,Seitan写道:
Hello,
I'm trying to do a promql query to select only hosts, that don't have specific label on them.
For example, selecting metrics from hosts who DO have label (type=value) works:

metrics_name * on (hostname) another_metrics{type="value"}

Problem is when i try to do same select against hosts without that label:


metrics_name * on (hostname) (absent(another_metrics{type="value"}))

this query gives no results.
Is there any way to do such query?
Thank you


--
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 promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages