@moris1amar (Moris Amar) posted a new topic, subject "How to define a time interval each day when alert threshold is enable?". It read:

   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.
    
    thanks,  
    Maurice

Then @emiltullstedt (Emiltullstedt) said

    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.

@moris1amar (Moris Amar) replied

    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?

@emiltullstedt (Emiltullstedt) replied

    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.

To which @jarkko1 (Jarkko Hyytiäinen) replied

    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):
    
    Just because I/1 can – 10 May 20
    
    ### Data from home – alerting and water shutoff (Part 5)
    
    Couple of examples of alerting with Grafana and reacting to those with IFTTT. Building an example of how to protect from water leaks with these techniques.

@lulzimbulica (GrafanaFan) replied

    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.
    [code] 
        (100-(avg by (instance) (irate(windows_cpu_time_total{job=~"windows_scrape",mode="idle"}[2m])) * 100)) * ((hour() > 8) * (hour() < 10))
        
    [/code]
    
    This returns _no data_. Any idea how can i bring this running? Thank you!

To which @doncucumber (Doncucumber) replied

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

Then @joricastrog (Ricardo Castro) said

    I have the same question

So @joeb-grafana (Joeblubaugh) replied

    If using the latest Grafana Alerting, you can do this using “Mute Timings” instead of trying to modify your alert rule queries. Instead of modifying your rules, you apply mute timings with label matchers so that a given notification policy will not send notifications.
    
    Grafana Labs
    
    ### Mute timings
    
    Mute timings
    
    Alert rules generate alerts, and notification policies send those alerts. Notification policies won't send when there is a silence (a one-time thing) or a mute policy (recurring thing) suppressing that policy.


{'source': 'discourse', 'url': 'https://community.grafana.com/t/how-to-define-a-time-interval-each-day-when-alert-threshold-is-enable/31694', 'title': 'How to define a time interval each day when alert threshold is enable?', 'views': 9524, 'has_accepted_answer': False, 'word_count': 435, 'like_count': 4, 'reply_count': 3, 'participant_count': 7, 'posts': 9, 'tags': 'alerting', 'author': '@moris1amar (Moris Amar)', 'participants': '@moris1amar (Moris Amar), @emiltullstedt (Emiltullstedt), @jarkko1 (Jarkko Hyytiäinen), @lulzimbulica (GrafanaFan), @doncucumber (Doncucumber), @joricastrog (Ricardo Castro), @joeb-grafana (Joeblubaugh)', 'image_url': [None], 'created_at': '2020-06-08T09:35:01.203Z', 'last_posted_at': '2022-07-18T05:05:48.896Z'}