Combining Promql hour() and minute()

36 views
Skip to first unread message

Lucas Hellmann

unread,
Feb 17, 2020, 4:33:49 AM2/17/20
to Prometheus Users
Hi,

I'm trying to setup a silence for specific alert during a reboot window,
and I'm facing problems with the use of minute() and hour() functions.

I want to be able to silence alert for a period like 01:00 to 04:30.
When only using hour() I can get this :
(hour() >= 1) and hour() < 5
So I get all hour from 1 to 4 okay, but without the desired minutes after it.

And when trying to combine minute() and hour like this for example :
(minute() > 0 and minute() < 30 and hour() < 5) and hour() >= 1
I get the 30min period for all the hour between 1 and 4.

Does somebody know the right way for this to get the time from 1 to hours:minutes.
parenthesis doesn't seem to work like I want but that may be my bad for not understanding their uses in promql correctly.

Cheers,
Lucas H

Julien Pivotto

unread,
Feb 17, 2020, 4:42:31 AM2/17/20
to Lucas Hellmann, Prometheus Users
On 17 Feb 01:33, Lucas Hellmann wrote:
> Hi,
>
> I'm trying to setup a silence for specific alert during a reboot window,
> and I'm facing problems with the use of minute() and hour() functions.
>
> I want to be able to silence alert for a period like 01:00 to 04:30.
> When only using hour() I can get this :
> (hour() >= 1) and hour() < 5
> So I get all hour from 1 to 4 okay, but without the desired minutes after
> it.
>
> And when trying to combine minute() and hour like this for example :
> (minute() > 0 and minute() < 30 and hour() < 5) and hour() >= 1
> I get the 30min period for all the hour between 1 and 4.

hour() >= 1 and hour() < 5 unless (hour() > 4 and minutes() > 30).

However, adding a daily cron job to your alertmanager that creates a
silence might be a better solution

>
> Does somebody know the right way for this to get the time from 1 to
> hours:minutes.
> parenthesis doesn't seem to work like I want but that may be my bad for not
> understanding their uses in promql correctly.
>
> Cheers,
> Lucas H
>
> --
> 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/3406e8c9-dbfb-46d4-9eb6-2bed413cc9b6%40googlegroups.com.


--
(o- Julien Pivotto
//\ Open-Source Consultant
V_/_ Inuits - https://www.inuits.eu
signature.asc

Lucas Hellmann

unread,
Feb 17, 2020, 4:51:03 AM2/17/20
to Prometheus Users
Hi,

Thanks for the input !
Yes I was going to look over cron job for some others alert related issues so I'll try to implement it this way too !

Le lundi 17 février 2020 10:42:31 UTC+1, Julien Pivotto a écrit :
On 17 Feb 01:33, Lucas Hellmann wrote:
> Hi,
>
> I'm trying to setup a silence for specific alert during a reboot window,
> and I'm facing problems with the use of minute() and hour() functions.
>
> I want to be able to silence alert for a period like 01:00 to 04:30.
> When only using hour() I can get this :
> (hour() >= 1) and hour() < 5
> So I get all hour from 1 to 4 okay, but without the desired minutes after
> it.
>
> And when trying to combine minute() and hour like this for example :
> (minute() > 0 and minute() < 30 and hour() < 5) and hour() >= 1
> I get the 30min period for all the hour between 1 and 4.

hour() >= 1 and hour() < 5 unless (hour() > 4 and minutes() > 30).

However, adding a daily cron job to your alertmanager that creates a
silence might be a better solution

>
> Does somebody know the right way for this to get the time from 1 to
> hours:minutes.
> parenthesis doesn't seem to work like I want but that may be my bad for not
> understanding their uses in promql correctly.
>
> Cheers,
> Lucas H
>
> --
> 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