# Trigger an alarm when no data received or no more data received

**URL:** <https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989>\
**Category:** PromQL\
**Created:** [October 30, 2023, 5:39pm UTC](https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989 "2023-10-30T17:39:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![benoittgt](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/benoittgt/32/839_2.png) [@benoittgt](https://discuss.prometheus.io/u/benoittgt)\
**Post date:** [October 30, 2023, 5:39pm UTC](https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989/1 "2023-10-30T17:39:28Z")

</div>

Hello

I am building a alerting mechanism an also a graph when I need to inform when there is no data coming since 6 hours (missing or no increase). I need to count only office opening hours (from 8am to 7pm, no week-ends).  
So if I had no data yesterday since 4pm. I will be notified only at 11am today.

I have something that is pretty good for missing data (only for weekday opening hours for the moment)

```auto
absent_over_time(data_flux{country="Country"}[6h]) if (hour() > 8 < 19) 

```

But I am trying to do the same when there is no increase.

I tried to look at other `_over_time` but didn’t found the right function. I also tried to offset, but with the “only opening hours” it is not easy to find a path.

If I try something like

```auto
sum(max_over_time(data_flux{country="Country"}[2h]))

```

It never goes to 0.

 ![Screenshot_2023-10-30_at_18_53_26](https://europe1.discourse-cdn.com/flex017/uploads/prometheus/original/1X/b33aae655df58c77a63b02669f0ccaa389a76b20.jpeg)

---

<div class="post-metadata">

**Author:** ![benoittgt](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/benoittgt/32/839_2.png) [@benoittgt](https://discuss.prometheus.io/u/benoittgt)\
**Post date:** [October 30, 2023, 6:03pm UTC](https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989/2 "2023-10-30T18:03:00Z")

</div>

I think I might have found the solution but it is not yet ok with the “only working hours” interval.

```auto
sum(max_over_time(increase(data_flux{country="country"}[$__rate_interval])[6h]) if (hour() > 8 < 18))

```

---

<div class="post-metadata">

**Author:** ![salessandri](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/salessandri/32/814_2.png) [@salessandri](https://discuss.prometheus.io/u/salessandri)\
**Post date:** [November 4, 2023, 5:12am UTC](https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989/3 "2023-11-04T05:12:57Z")

</div>

The fact that the condition does not apply during the closed hours but should continue where it left off I think is not going to be really easy to overcome. What I mean by this is the fact that if you start missing data 2 hours before closing time Friday, when opening time Mon arrives the “remaining time” before trigger is 4 hours rather than six. I don’t see an easy way to overcome this, at least at first glance.

For alerting, you can take advantage of the `for: <time-range>` on the rule definition while leveraging `[mute|active]_time_intervals` in the alert manager configuration to achieve what you want.  
By doing this you wouldn’t need to use `*_over_time()` functions nor `hour()` conditionals.

Source:

[1] [Alerting Docs](https://prometheus.io/docs/alerting/latest/configuration/#inhibition-related-settings)  
[2] [Alert Rules Docs](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/)

---

<div class="post-metadata">

**Author:** ![benoittgt](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/benoittgt/32/839_2.png) [@benoittgt](https://discuss.prometheus.io/u/benoittgt)\
**Post date:** [November 6, 2023, 9:39am UTC](https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989/4 "2023-11-06T09:39:13Z")

</div>

Thanks for your answer.

`absent_over_time` works well but I need to have missing data instead of 0. Do you know how to trick data an replace 0 to `NoData` ?

---

<div class="post-metadata">

**Author:** ![salessandri](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/salessandri/32/814_2.png) [@salessandri](https://discuss.prometheus.io/u/salessandri)\
**Post date:** [November 6, 2023, 3:16pm UTC](https://discuss.prometheus.io/t/trigger-an-alarm-when-no-data-received-or-no-more-data-received/1989/5 "2023-11-06T15:16:51Z")

</div>

you can use a condition (like `promql-query > 0`). That will basically remove all datapoints from that time-series that not match the condition.
