<p>I want to calculate the CPU and Memory Percentage of Resource utilization of an individual pod in Kubernetes. For that, I am using metrics server API</p>

<ol>
<li>From the metrics server, I get the utilization from this command</li>
</ol>

<p>kubectl top pods --all-namespaces</p>

<pre><code>kube-system   coredns-5644d7b6d9-9whxx                   2m           6Mi
kube-system   coredns-5644d7b6d9-hzgjc                   2m           7Mi
kube-system   etcd-manhattan-master                      10m          53Mi
kube-system   kube-apiserver-manhattan-master            23m          257Mi
</code></pre>

<p>But I want the percentage utilization of individual pod Both CPU % and MEM%</p>

<p>From this output by top command it is not clear that from how much amount of cpu and memory it consumes the resultant amount?</p>

<p>I don't want to use Prometheus operator I saw one formula for it</p>

<pre><code>sum (rate (container_cpu_usage_seconds_total{image!=""}[1m])) by (pod_name)
</code></pre>

<p>Can I calculate it with <a href="https://github.com/kubernetes-sigs/metrics-server" rel="noreferrer">MetricsServer</a> API?</p>

<p>I thought to calculate like this </p>

<p><strong>CPU%</strong> = ((2+2+10+23)/ Total CPU MILLICORES)*100</p>

<p><strong>MEM%</strong> = ((6+7+53+257)/AllocatableMemory)* 100</p>

<p>Please tell me if I right or wrong. Because I didn't see any standard formula for calculating pod utilization in Kubernetes documentation</p>

<p>Unfortunately <code>kubectl top pods</code> provides only a <a href="https://github.com/DirectXMan12/k8s-prometheus-adapter/blob/master/docs/walkthrough.md#quantity-values" rel="nofollow noreferrer">quantity values</a> and not a percentages.</p>

<p><a href="https://github.com/kubernetes-sigs/metrics-server/issues/193#issuecomment-451309811" rel="nofollow noreferrer">Here</a> is a good explanation of how to interpret those values.</p>

<p>It is currently not possible to list pod resource usage in percentages with a <code>kubectl top</code> command.</p>

<p>You could still chose <a href="https://prometheus.io/docs/visualization/grafana/" rel="nofollow noreferrer">Grafana with Prometheus</a> but it was already stated that you don't want to use it (however maybe another member of the community with similar problem would do so I am mentioning it here).</p>

<p><strong>EDIT:</strong></p>

<p>Your formulas are correct. They will calculate how much CPU/Mem is being consumed by all Pods relative to total CPU/Mem you got. </p>

<p>I hope it helps. </p>
