# Count Consecutive Minutes a Metric Exceeds Threshold Using DQL

**URL:** <https://community.dynatrace.com/t/count-consecutive-minutes-a-metric-exceeds-threshold-using-dql/51731>\
**Category:** DQL\
**Tags:** dql, kafka, dynatrace-managed, anomaly-detection\
**Created:** [May 21, 2025, 1:03pm UTC](https://community.dynatrace.com/t/count-consecutive-minutes-a-metric-exceeds-threshold-using-dql/51731 "2025-05-21T13:03:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omerre](https://avatars.discourse-cdn.com/v4/letter/o/47e85d/32.png) [@Omerre](https://community.dynatrace.com/u/Omerre)\
**Post date:** [May 21, 2025, 1:03pm UTC](https://community.dynatrace.com/t/count-consecutive-minutes-a-metric-exceeds-threshold-using-dql/51731/1 "2025-05-21T13:03:24Z")

</div>

Hey all,  
I need to create an alert when a certain metric\* is above a threshold for more than 2 hours. Since the maximum length of the Anomaly Detection sliding window is 60 minutes, I thought of this workaround:

creating a DQL query that would chart **how&nbsp;many consecutive minutes this metric was above the threshold** , and create an&nbsp; **alert when this value exceeds 120**. Is this possible?

Thanks!

\*_confluent\_kafka\_server\_consumer\_lag\_offsets_

---

<div class="post-metadata">

**Author:** ![yanezza](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yanezza/32/5036_2.png) [@yanezza](https://community.dynatrace.com/u/yanezza)\
**Post date:** [May 21, 2025, 8:22pm UTC](https://community.dynatrace.com/t/count-consecutive-minutes-a-metric-exceeds-threshold-using-dql/51731/2 "2025-05-21T20:22:40Z")

</div>

Hi,

In your case, I recommend adjusting the alerting profile. You can configure it to generate a problem when the metric shows an anomaly—this can be based on a 5-minute sliding window, for example.

To reduce noise, you can set the alert to trigger only if the problem remains open for at least 2 hours before sending a notification.

You can use DQL with a count function only if it is a static threshold that you know (so you can put it in the DQL query).

Let me know if you need help setting this up!

---

<div class="post-metadata">

**Author:** ![Omerre](https://avatars.discourse-cdn.com/v4/letter/o/47e85d/32.png) [@Omerre](https://community.dynatrace.com/u/Omerre)\
**Post date:** [May 25, 2025, 6:48am UTC](https://community.dynatrace.com/t/count-consecutive-minutes-a-metric-exceeds-threshold-using-dql/51731/3 "2025-05-25T06:48:06Z")

</div>

Hi yanezza, thank you for your help!  
The thing is a normal behavior in our case always includes periodic spikes. Our concern is when the **duration** of the spikes exceeds some threshold, and not necessarily abnormality with the metric values.

 ![Omerre_0-1748154988516.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/4/c4b3fd09db096db4182e3609ab5dfbc8d9ee60f5.png)

Although your suggestion might help with sending notifications when a real problem will arise, it would still fill our environment with huge number of false problems.

Is there any proper way to handle this with DQL? i.e. instead of getting the resulted metric values by time, we would like to get the resulted&nbsp; **duration** of certain metric values.

---

<div class="post-metadata">

**Author:** ![izabelarokita](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/izabelarokita/32/41812_2.png) [@izabelarokita](https://community.dynatrace.com/u/izabelarokita)\
**Post date:** [December 18, 2025, 10:45am UTC](https://community.dynatrace.com/t/count-consecutive-minutes-a-metric-exceeds-threshold-using-dql/51731/4 "2025-12-18T10:45:36Z")

</div>

Hey&nbsp;[@Omerre](https://community.dynatrace.com/user/87132)&nbsp;,  
I just wanted to check in and see if you still need help with this. If so, I’d be happy to look into it for you!&nbsp;:blush:  
Please let me know what works best for you.
