# Creating a dashboard with a formula "percentage of Kubernetes pod usage (requests/limits)"

**URL:** <https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546>\
**Category:** Dashboarding\
**Tags:** request-attributes, dashboards-classic, kubernetes\
**Created:** [February 22, 2023, 5:13pm UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546 "2023-02-22T17:13:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shakib](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@shakib](https://community.dynatrace.com/u/shakib)\
**Post date:** [February 22, 2023, 5:13pm UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546/1 "2023-02-22T17:13:40Z")

</div>

So I am able to see a % of the CPU being requested per pods compared to the limit of the CPU on said pod using the following formual:

(  
builtin:cloud.kubernetes.pod.cpuRequests:last:splitBy(“dt.entity.cloud\_application\_instance”)  
/ builtin:cloud.kubernetes.pod.cpuLimits:last:splitBy(“dt.entity.cloud\_application\_instance”)  
\* 100  
):setUnit(Percent):sort(value(sum,descending))

But I am trying to add a filter to this by saying that I only want the data with a specific K8 cluster. When I create a dashboard tile for the above formula and then I add a dynamic filter on the dashboard to limit by a specific Kubernete Cluster, that dynamic filter doesn’t work.

So, I am now trying to enter a Kubernete cluster filter into the formula but I’m running into issues. Any suggestions on how I can achieve this? I tried adding things like “dt.entity.kuberentes\_cluster” at the end of both metrics like below, but it does not work.

(  
builtin:cloud.kubernetes.pod.cpuRequests:last:splitBy(“dt.entity.cloud\_application\_instance”, “dt.entity.kubernetes\_cluster”)  
/ builtin:cloud.kubernetes.pod.cpuLimits:last:splitBy(“dt.entity.cloud\_application\_instance”,“dt.entity.kubernetes\_cluster”)  
\* 100  
):setUnit(Percent):sort(value(sum,descending))

---

<div class="post-metadata">

**Author:** ![shakib](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@shakib](https://community.dynatrace.com/u/shakib)\
**Post date:** [February 22, 2023, 5:18pm UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546/2 "2023-02-22T17:18:44Z")

</div>

So in this example below I see a % of the CPU requested from the allocated on a Node. I want this same data at the pod level, which is what I am trying to find out in my formula above.

(  
builtin:kubernetes.node.requests\_cpu:last:splitBy(“dt.entity.kubernetes\_node”,“dt.entity.kubernetes\_cluster”):sum  
/ builtin:kubernetes.node.cpu\_allocatable:last:splitBy(“dt.entity.kubernetes\_node”,“dt.entity.kubernetes\_cluster”):sum  
\* 100  
):setUnit(Percent):sort(value(sum,descending))

---

<div class="post-metadata">

**Author:** ![shakib](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@shakib](https://community.dynatrace.com/u/shakib)\
**Post date:** [February 22, 2023, 5:39pm UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546/3 "2023-02-22T17:39:19Z")

</div>

Ok I figured out how to get it to work with an environment tag filter. But the problems Dynatrace is reporting to me are different than the ones I am seeing from my formula which now looks like:

(builtin:cloud.kubernetes.pod.cpuRequests:filter(and(or(in(“dt.entity.cloud\_application\_instance”,entitySelector(“type(cloud\_application\_instance),fromRelationship.runsOn(type(KUBERNETES\_NODE),tag(~“Environment:TagHERE~”))”))))):splitBy(“dt.entity.cloud\_application\_instance”) / builtin:cloud.kubernetes.pod.cpuLimits:filter(and(or(in(“dt.entity.cloud\_application\_instance”,entitySelector(“type(cloud\_application\_instance),fromRelationship.runsOn(type(KUBERNETES\_NODE),tag(~“Environment:TagHERE~”))”))))):splitBy(“dt.entity.cloud\_application\_instance”) \* 100 ) :sort(value(auto,descending)):setUnit(Percent)

I guess this means that the CPU request saturation alerts that Dynatrace is showing me (which are worthless as they point to a Node and not an actual Pod that I can point to and say this is the problem one) are using some other statistic.

---

<div class="post-metadata">

**Author:** ![florian\_g](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/florian_g/32/12081_2.png) [@florian\_g](https://community.dynatrace.com/u/florian_g)\
**Post date:** [June 5, 2023, 7:20am UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546/4 "2023-06-05T07:20:50Z")

</div>

Hi 👋,

Here are a few thoughts from my end - I hope they help 🙂

1. The metrics you’re using in your expression are meanwhile deprecated. I recommend using the following alternative:  
(  
builtin:kubernetes.workload.requests\_cpu:last:splitBy(“dt.entity.cloud\_application”, “dt.entity.kubernetes\_cluster”)  
/ builtin:kubernetes.workload.limits\_cpu:last:splitBy(“dt.entity.cloud\_application”,“dt.entity.kubernetes\_cluster”)  
\* 100  
):setUnit(Percent):sort(value(sum,descending))

2. I’m interested in the use-case behind the expression: Why do you want to know CPU requests compared to limits on a pod level? What I usually see is people comparing

Best,

Florian

---

<div class="post-metadata">

**Author:** ![PeterDrenth1](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PeterDrenth1](https://community.dynatrace.com/u/PeterDrenth1)\
**Post date:** [July 29, 2024, 6:52am UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546/5 "2024-07-29T06:52:27Z")

</div>

When someone is running a multitenant environment, you usually put limits on how much CPU per namespace, not per workload.&nbsp; When customers need higher than alloted CPU or MEM, they can be given more on a per namespace/tenant basis, often ppl will request too much per pod.&nbsp; where they only use maybe 1% of what they really requested for the pod.&nbsp; In this case you want to be able to show them when they are simply requesting too much for other pods and that 's why they run into limits.&nbsp; Again .. this is not workload or node based limits.&nbsp; So I do understand the question of initial poster. ( Even though I also don’t have the answer )

Kind rgds,

Peter

---

<div class="post-metadata">

**Author:** ![florian\_g](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/florian_g/32/12081_2.png) [@florian\_g](https://community.dynatrace.com/u/florian_g)\
**Post date:** [July 29, 2024, 9:19am UTC](https://community.dynatrace.com/t/creating-a-dashboard-with-a-formula-percentage-of-kubernetes-pod-usage-requests-limits/38546/6 "2024-07-29T09:19:56Z")

</div>

thx - if this is about namespace quotas, you can get these insights quickly in our [new Kubernetes app](https://www.dynatrace.com/technologies/kubernetes-monitoring/) on the namespace screens. You can see the total of requested CPU/Mem vs. actual usage. Further below, we display how much CPU/Mem requests are being used out of the defined quota.

 ![florian_g_0-1722244616513.png](https://global.discourse-cdn.com/dynatrace/original/3X/2/2/2280d8c5232196a18cf4060596202a71149fa884.png)
