How to define a time interval each day when alert threshold is enable?

Hi, I want to relate only of a part of the day (between 2 hours e.g. 11AM and 11PM) about the value given. Also, I want to set a threshold (alert) only during this time in order to receive only relevant notification.


1 Like

What datasource are you using?

Could you explain a little more what it is you want to accomplish? I’m a little confused by the time range description, as there are twelve hours between 11:00 and 23:00 and you’re talking about two hours.

Hi, I use prometheus as data source and I refer for example to a time interval (12 hours) i.e. between 11AM-11PM.
And only during this time, I want to define a threshold in alert. is it possible?

It’s kind of possible with Prometheus but not with Grafana. If you write sum(<metric>) * ((hour() > bool 11) * (hour() < bool 23)) you get a series where every hour which isn’t between 11:00-23:00 (UTC, you’ll have to adjust accordingly) is 0. I can’t seem to remember how to do that if you wanted to keep any labels though.

I have also been trying to find a best way for something like this. Not perfect yet but this is what I came up with. I also have Prometheus as db.:

Use hour() query for handling when the alerts are active and relative time range for displaying only parts of a day in the dashboard (now/d-2h to now/d+6h-1d):

Hi, thank you for your suggestion. This works when using some query returning single value, but not the ones which return values from different targets, or im doing something wrong.

(100-(avg by (instance) (irate(windows_cpu_time_total{job=~"windows_scrape",mode="idle"}[2m])) * 100)) * ((hour() > 8) * (hour() < 10))

This returns no data. Any idea how can i bring this running? Thank you!

@emiltullstedt is this possible to do with InfluxDB as DS? Thanks!