# How to filter built-in CPU usage metric by cluster and namespace and get max per workload?

**URL:** <https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233>\
**Category:** Container platforms\
**Tags:** dql, openshift, dynatrace-managed, data-explorer, container, kubernetes, cpu\
**Created:** [September 4, 2025, 12:47pm UTC](https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233 "2025-09-04T12:47:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aboud1](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Aboud1](https://community.dynatrace.com/u/Aboud1)\
**Post date:** [September 4, 2025, 12:47pm UTC](https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233/1 "2025-09-04T12:47:45Z")

</div>

Hi Community,

I’m using the built-in metric query in Dynatrace for CPU usage per workload, for example:

builtin:containers.cpu.usageMilliCores:filter(in(“dt.entity.container\_group\_instance”, entitySelector(“type(CONTAINER\_GROUP\_INSTANCE), fromRelationships.IS\_CGI\_OF\_CA(type(CLOUD\_APPLICATION), entityId(CLOUD\_APPLICATION-XXXXX))”))):parents:parents:splitBy(“dt.entity.cloud\_application”):sum

👉 This built-in [used by dynatrace by default] works perfectly when I analyze a single workload.

What I want to achieve:

- Get the **maximum CPU usage (peak value)** per workload
- For **all workloads** inside a specific **cluster (OpenShift Main-Cluster)** and a specific **namespace (dxl-vf-consumer)**
- Without having to check each workload individually.

My challenge:  
I’m not sure how to **add the cluster + namespace filters** into this built-in query.

**Question:**  
How can I adjust this built-in query to include cluster and namespace filters so that it returns the **max CPU usage per workload** within that scope?

---

<div class="post-metadata">

**Author:** ![p\_devulapalli](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/p_devulapalli/32/41590_2.png) [@p\_devulapalli](https://community.dynatrace.com/u/p_devulapalli)\
**Post date:** [September 5, 2025, 12:26am UTC](https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233/2 "2025-09-05T00:26:55Z")

</div>

[@Aboud1](https://community.dynatrace.com/user/90253)&nbsp;Can you please try the below and see if it helps ?

```markup
builtin:kubernetes.workload.cpu_usage:filter(and(or(in("dt.entity.cloud_application_namespace",entitySelector("type(cloud_application_namespace),entityName.equals(~"namespace_abc~")"))),or(in("dt.entity.kubernetes_cluster",entitySelector("type(kubernetes_cluster),entityName.equals(~"cluster_xyz~")"))))):splitBy("k8s.workload.name"):max:sort(value(max,descending))

```

---

<div class="post-metadata">

**Author:** ![Aboud1](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Aboud1](https://community.dynatrace.com/u/Aboud1)\
**Post date:** [September 10, 2025, 6:01am UTC](https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233/3 "2025-09-10T06:01:42Z")

</div>

Hello&nbsp;[@p\_devulapalli](https://community.dynatrace.com/user/21657)

Thanks for your reply 🙏

I tried the query you suggested with builtin:kubernetes.workload.cpu\_usage and it works fine in terms of filtering by cluster and namespace.

But what I noticed is that the values are quite different from the ones I get when using builtin:containers.cpu.usageMilliCores (the metric I shared in my original question).

Especially during spikes, the difference becomes very large.  
For example:

- At **2025-09-03 02:17** , using containers.cpu.usageMilliCores, the CPU usage for a workload was **1.29 cores**.
- At the exact same time, with kubernetes.workload.cpu\_usage, it showed only **496 millicores**.

When there’s no spike, the values are close, but during peaks the workload metric seems much lower.

So my question is:  
👉 Why does this difference happen? Is the workload metric doing some kind of aggregation that smooths out spikes? If yes, does that mean it’s less accurate for identifying peak usage per workload?

---

<div class="post-metadata">

**Author:** ![p\_devulapalli](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/p_devulapalli/32/41590_2.png) [@p\_devulapalli](https://community.dynatrace.com/u/p_devulapalli)\
**Post date:** [September 10, 2025, 9:46am UTC](https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233/4 "2025-09-10T09:46:18Z")

</div>

[@Aboud1](https://community.dynatrace.com/user/90253)&nbsp;There is a bit of difference between both the queries

_builtin:containers.cpu.usageMilliCores:_ This metric represents CPU usage at the **container** level, measured in millicores. It provides detailed insights into individual container performance.

_builtin:kubernetes.workload.cpu\_usage:_ This metric aggregates CPU usage at the **workload** level, which includes all containers within a specific Kubernetes workload (e.g., Deployment, StatefulSet). Ideally this might include more than one container/pod as per the workload specifications

Since you mentioned about reporting on " **max CPU usage per workload"** I’ve suggested using&nbsp;_builtin:kubernetes.workload.cpu\_usage_ as it aggregates CPU usage at the workload level and also allows us to split the data by dimensions we are after unlike&nbsp;_builtin:containers.cpu.usageMilliCores_ which do not provide those dimensions

Alternatively, if you are on SaaS you can extract the container level CPU using the below DQL with the needed dimensions

Hope this helps

```markup
timeseries max(dt.kubernetes.container.cpu_usage), 
by: { k8s.container.name, k8s.pod.name }, 
filter: { matchesValue(entityAttr(dt.entity.kubernetes_cluster, "entity.name"), "cluster_xyz") AND matchesValue(entityAttr(dt.entity.cloud_application_namespace, "entity.name"), "namespace_abc") }

```

---

<div class="post-metadata">

**Author:** ![Aboud1](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Aboud1](https://community.dynatrace.com/u/Aboud1)\
**Post date:** [September 16, 2025, 5:12am UTC](https://community.dynatrace.com/t/how-to-filter-built-in-cpu-usage-metric-by-cluster-and-namespace-and-get-max-per-workload/53233/5 "2025-09-16T05:12:53Z")

</div>

Thanks a lot [@p\_devulapalli](https://community.dynatrace.com/user/21657) for the detailed clarification 🙏

Now it’s much clearer why the values differ between:

- **builtin:containers.cpu.usageMilliCores** → container-level, more accurate for spikes
- **builtin:kubernetes.workload.cpu\_usage** → workload-level, aggregated across containers, so spikes appear lower

My main objective is still to get the **peak CPU usage per workload** in a given **cluster + namespace**.

As you mentioned, DQL would indeed solve this by combining container-level accuracy with the right filters. Unfortunately, I’m on **Dynatrace Managed** , so I don’t have DQL available — and that’s where the limitation bites me.

So basically, I need to decide between:

- **Accuracy (container-level)** but no cluster/namespace filters, or
- **Scope (workload-level with filters)** but with aggregated values.

That explains the behavior I was seeing. Thanks again for the guidance 🙌
