prometheus up query

53 views
Skip to first unread message
Message has been deleted

Sesha kumari

unread,
Jul 28, 2022, 11:11:22 PM7/28/22
to Prometheus Users
Hello all,

I installed node exporter on 10 servers. among those servers few servers are down. I want to know which servers are down from last 7 days.

up{instance=~"$instance"} == 0 (this is the query to find which server was down) but how can i pass the time like last 7 days which server was down and so on

Any leads?

Thanks,
kumari.

Brian Candler

unread,
Jul 29, 2022, 2:42:15 AM7/29/22
to Prometheus Users
up{instance=~"$instance"} offset 7d == 0             # servers which were down at a single instant of time exactly 7 days ago
max_over_time(up{instance=~"$instance"}[7d]) == 0    # servers which have been down *for the whole* of the last 7 days
min_over_time(up{instance=~"$instance"}[7d]) == 0    # servers which have been down *at any time* over the last 7 days
avg_over_time(up{instance=~"$instance"}[7d]) < 0.9   # servers which have been down *for at least 10%* of the last 7 days

Sesha kumari

unread,
Jul 29, 2022, 3:45:05 AM7/29/22
to Prometheus Users
Thanks for your support.. Its working fine foe 7 days. But If I keep 30 days in place of 7 days it is throwing following error:

post http://1.1.1.1:9090/api/v1/query_range": net/http: timeout awaiting response headers

Brian Candler

unread,
Jul 29, 2022, 4:35:11 AM7/29/22
to Prometheus Users
If Grafana is calling calling the query_range endpoint rather than query, then you are running a *graph* of this query (swept over a time range) instead of an *instant* query.  This query will be very expensive: it will effectively be repeating the same query from time T1 to time T2, at some interval, but each step looks back over 30 days of data.

You need to run this as an *instant* query.  It will then tell you servers which have been down between the current instant and whatever offset you put in.

I would expect that a grafana *variable* query would be an instant query.  However you definitely don't want to use an expression like this as something to draw a graph of.  In that case, you just want to draw a graph of "up".

Ben Kochie

unread,
Jul 29, 2022, 4:39:04 AM7/29/22
to Brian Candler, Prometheus Users
Yes, for Grafana you want use these kinds of queries:

Graph Panel: avg_over_time(up{instance=~"$instance"}[$__interval])
Stat Panel (instant): avg_over_time(up{instance=~"$instance"}[$__range])


--
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/3629df5a-5d6a-4924-bd0c-f5766db66aecn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages