# Count of memory usage breaches

**URL:** <https://community.dynatrace.com/t/count-of-memory-usage-breaches/43948>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, notebooks\
**Created:** [February 2, 2024, 11:01am UTC](https://community.dynatrace.com/t/count-of-memory-usage-breaches/43948 "2024-02-02T11:01:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uzahid](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@uzahid](https://community.dynatrace.com/u/uzahid)\
**Post date:** [February 2, 2024, 11:01am UTC](https://community.dynatrace.com/t/count-of-memory-usage-breaches/43948/1 "2024-02-02T11:01:56Z")

</div>

Hi,

I’m trying to get my query to return a count of breaches of a threshold for the memory usage on a set of server.

Unfortunately, i’m not quite being able to figure out that’s possible. The current query I have returns the max memory usage for the given hosts. How would I go about adding a count() feature to this?

timeseries usage=max(dt.host.memory.usage), by:{host.name}, interval:1h  
| filter host.name == “host1” OR host.name == “host2” OR host.name == “host3” OR host.name == “host4”

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [February 2, 2024, 10:02pm UTC](https://community.dynatrace.com/t/count-of-memory-usage-breaches/43948/2 "2024-02-02T22:02:46Z")

</div>

You can use iterative expression to compare each value of returned timeseries against threshold and put in breaches table 1 when&nbsp; it is crossed (otherwise 0). By summing elements of breaches table you get count of hours where memory usage was above certain level at least once:

```markup
timeseries usage=max(dt.host.memory.usage, default:0), interval:1h, by:{dt.entity.host}
, filter: { matchesValue(host.name,"*filter*", caseSensitive:false) }
| fieldsAdd breaches= if(usage[]>22,1,else:0) // my ex. threshold = 22
| fieldsAdd breachesCount=arraySum(breaches)

```

result of this query on my data looks like this:

 ![krzysztof_hoja_0-1706910733665.png](https://global.discourse-cdn.com/dynatrace/original/2X/6/670560bef75fcbbc4c0599328153734f0836fdeb.png)

you can also do the operation in single line using iCollectArray:

```markup
| fieldsAdd breachesCount= arraySum(iCollectArray(if(usage[]>22,1,else:0)))

```

Kris
