Last value(metric count) of a range vector

39 views
Skip to first unread message

Baitanik Talukder

unread,
Jun 15, 2020, 4:18:23 AM6/15/20
to Prometheus Users
I need the last value in a range vector.
Something like 

last_value(failure_count{job="xyz"}[5d])

it is need for the following scenrio:
for last 4 days there was no failure_count metric pushed.. so last value we have 5 days back.
output of 
failure_count{job="xyz"}[5d]

I need the last value (5) from here.

failure_count{endpoint="http",job="xyz"}8 @1591776884.502
1...@1591776914.502
9 @1591776944.502
5 @1591776974.502

Julien Pivotto

unread,
Jun 15, 2020, 4:23:49 AM6/15/20
to Baitanik Talukder, Prometheus Users
On 15 Jun 01:18, Baitanik Talukder wrote:
> I need the last value in a range vector.
> Something like
>
> *last_value*(failure_count{job="xyz"}[5d])
>
> it is need for the following scenrio:
> for last 4 days there was no failure_count metric pushed.. so last value we
> have 5 days back.
> output of
> failure_count{job="xyz"}[5d]
>
> I need the last value (5) from here.
>
> failure_count{endpoint="http",job="xyz"} 8 @1591776884.502
> 1...@1591776914.502
> 9 @1591776944.502
> 5 @1591776974.502

This feature has been requested many times

https://github.com/prometheus/prometheus/pull/1139
https://github.com/prometheus/prometheus/pull/6530
https://github.com/prometheus/prometheus/issues/7179
https://groups.google.com/g/prometheus-developers/c/_h6_QC1zC8U/m/815U0fxQBAAJ

But no consensus has been reached yet to accept that in Prometheus.

In the mean time you can +/- workaround this in recording rules
https://roidelapluie.be./blog/2019/02/21/prometheus-last/

>
> --
> 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/36ba6d12-ec84-43c3-980e-a38b5ce5e873o%40googlegroups.com.


--
Julien Pivotto
@roidelapluie

Baitanik Talukder

unread,
Jun 15, 2020, 5:45:03 AM6/15/20
to Prometheus Users
Okay.. if we try to do the workaround with recording rule.. please tell me how in this case..

just to get the latest know values from this blog (https://roidelapluie.be./blog/2019/02/21/prometheus-last/)

only this one is enough .. right ?

- record: available_sms_last expr: available_sms or available_sms_last

where available_sms is the actual metric

so my case I only have to add :

groups:
- name: test-rules rules: - expr: failure_count or failure_count_last record: failure_count_last
  - alert: failure_count_last_alert
               expr: failure_count_last_alert > 0

Brian Brazil

unread,
Jun 15, 2020, 5:51:44 AM6/15/20
to Baitanik Talukder, Prometheus Users
On Mon, 15 Jun 2020 at 09:18, Baitanik Talukder <baitanik...@gmail.com> wrote:
I need the last value in a range vector.
Something like 

last_value(failure_count{job="xyz"}[5d])

it is need for the following scenrio:


 
for last 4 days there was no failure_count metric pushed..

Can you explain more about what you mean about pushing a metric? Anything you pushed to the pushgateway should stay there forever, so it sounds like the issue here could be you using something suboptimally.

Brian

 
so last value we have 5 days back.
output of 
failure_count{job="xyz"}[5d]

I need the last value (5) from here.

failure_count{endpoint="http",job="xyz"}8 @1591776884.502
1...@1591776914.502
9 @1591776944.502
5 @1591776974.502

--
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/36ba6d12-ec84-43c3-980e-a38b5ce5e873o%40googlegroups.com.

Baitanik Talukder

unread,
Jun 15, 2020, 5:53:10 AM6/15/20
to Prometheus Users

that max_over_time or min_over_time can not be applied in my case , because I need recent value..
not the max or min value in that period..

Baitanik Talukder

unread,
Jun 15, 2020, 7:40:55 AM6/15/20
to Prometheus Users
Yeah it is pushed to pushgateway..
so here for last 4 days no metric was pushed to gateway.

Basically I need to check the last 3 known values and based on that raise alert.
most recent count > 0 : raise alert warning
most recent 2 consecutive count > 0 : raise alert severe
most recent 3 consecutive count > 0 : raise alert critical 

How do I do it in prometheus rule ?

On Monday, 15 June 2020 13:48:23 UTC+5:30, Baitanik Talukder wrote:
Message has been deleted

Brian Brazil

unread,
Jun 15, 2020, 8:45:45 AM6/15/20
to Baitanik Talukder, Prometheus Users
On Mon, 15 Jun 2020 at 12:41, Baitanik Talukder <baitanik...@gmail.com> wrote:
Yeah it is pushed to pushgateway..
so here for last 4 days no metric was pushed to gateway.

Basically I need to check the last 3 known values and based on that raise alert.
most recent count > 0 : raise alert warning
most recent 2 consecutive count > 0 : raise alert severe
most recent 3 consecutive count > 0 : raise alert critical 
 
How do I do it in prometheus rule ?

Prometheus is not an event logging system, so that would be quite difficult.

The usual way to do this is to push a gauge when things succeed whose value is the current time - and then alert when that's too long ago by comparing with time().

Brian
 

On Monday, 15 June 2020 13:48:23 UTC+5:30, Baitanik Talukder wrote:
I need the last value in a range vector.
Something like 

last_value(failure_count{job="xyz"}[5d])

it is need for the following scenrio:
for last 4 days there was no failure_count metric pushed.. so last value we have 5 days back.
output of 
failure_count{job="xyz"}[5d]

I need the last value (5) from here.

failure_count{endpoint="http",job="xyz"}8 @1591776884.502
1...@1591776914.502
9 @1591776944.502
5 @1591776974.502

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