<p>I am trying to see how much memory and CPU is utilized by a kubernetes pod. I ran the following command for this:</p>

<pre><code>kubectl top pod podname --namespace=default
</code></pre>

<p>I am getting the following error:</p>

<pre><code>W0205 15:14:47.248366    2767 top_pod.go:190] Metrics not available for pod default/podname, age: 190h57m1.248339485s
error: Metrics not available for pod default/podname, age: 190h57m1.248339485s
</code></pre>

<ol>
<li>What do I do about this error? Is there any other way to get CPU and memory usage of the pod?</li>
<li><p>I saw the sample output of this command which shows CPU as 250m. How is this to be interpreted?</p></li>
<li><p>Do we get the same output if we enter the pod and run the linux <code>top</code> command?</p></li>
</ol>

aniztar
<blockquote>
<p>CHECK WITHOUT METRICS SERVER or ANY THIRD PARTY TOOL</p>
</blockquote>
<hr />
<p>If you want to check pods cpu/memory usage without installing any third party tool then you can get memory and cpu usage of pod from cgroup.</p>
<ol>
<li>Go to pod's exec mode <code>kubectl exec -it pod_name -n namespace -- /bin/bash</code></li>
<li>Run <code>cat /sys/fs/cgroup/cpu/cpuacct.usage</code> for cpu usage</li>
<li>Run <code>cat /sys/fs/cgroup/memory/memory.usage_in_bytes</code> for memory usage</li>
</ol>
<p><em>Make Sure you have added the resources section (requests and limits) to deployment so that it can calculate the usage based on cgroup and container will respect the limits set on pod level</em></p>
<blockquote>
<p>NOTE: This usage is in bytes. This can vary upon pod usage and these values changes frequently.</p>
</blockquote>
