<p>How to get the CPU usage of a pod in a namespace ? My initial dashboard on Grafana setup looks like this -
<a href="https://i.stack.imgur.com/fI8fF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fI8fF.png" alt="enter image description here" /></a></p>
<p>I'm trying to come up with a query, that gives me the CPU usage of a selected <strong>pod</strong> of selected <strong>namespace</strong> in selected <strong>cluster</strong>. Managed to come up with below one, but it returns &quot;<code>No data</code>&quot;.</p>
<pre><code>sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{pod=&quot;$pod&quot;, namespace=&quot;$namespace&quot;})
</code></pre>
<p>Where am I going wrong ?</p>

Chel MS
<p>If you want to calculate the workload CPU utilization per pod, in terms of usage seconds of CPU, you can use this <code>PromQL</code> query:</p>
<pre><code>sum(rate(container_cpu_usage_seconds_total{namespace=&quot;$namespace&quot;,
  pod_name=~&quot;$podName&quot;,container_name!=&quot;&quot;}[1m])) by (pod_name)
</code></pre>
<p>where:</p>
<ul>
<li><code>container_cpu_usage_seconds_total()</code> which gives you how long the CPU has been occupied</li>
<li><code>rate()</code> calculates the per-second average rate of increase of the time series in the range vector</li>
<li><code>[1m]</code> reads the values at the defined interval of 1 minute</li>
<li><code>sum() by (pod_name)</code> adds all values which contain the same pod names, necessary in case of multiple containers in the same pod</li>
<li><code>namespace=&quot;$namespace&quot;,pod_name=~&quot;$podName&quot;,container_name!=&quot;&quot;</code> applies the condition to get the pods to consider and filter the rest</li>
</ul>
<p>If you want to calculate the workload memory utilization per pod, you can use this query:</p>
<pre><code>sum(container_memory_working_set_bytes{namespace=&quot;$namespace&quot;,
  pod_name=~&quot;$podName&quot;, container_name!=&quot;&quot;}) by (pod_name)
</code></pre>
