> For the complete documentation index, see [llms.txt](https://learn.farizizwan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.farizizwan.com/devops-and-devsecops/kubernetes/fundamental/cluster-cpu-and-memory-inspections.md).

# Cluster CPU & Memory Inspections

## Quickly get the summary of total CPU&#x20;

```bash
$ kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.cpu}{"\n"}{end}' | awk '{sum += $2} END {print "Total CPUs across all nodes: " sum}'
```

## Quickly get the summary of total Memory

```bash
$ kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.memory}{"\n"}{end}' | awk '{print $1 "\t" $2 / (1024 * 1024) " MB"}'
```

## Inspect Current Utilization&#x20;

Ensure that Metrics Server is installed in your Kubernetes cluster. If it's installed, you can query it to get CPU and memory usage information.

<pre class="language-bash"><code class="lang-bash"><strong>$ kubectl top nodes
</strong></code></pre>

Run below command to convert from Mebibytes (Mi) to Megabytes (MB)

```bash
$ kubectl top nodes | awk '{print $1, $2, $3, $4, ($5/1024/1024)"MB", $6}'
```

## Using Kubernetes Dashboard&#x20;

If you have Kubernetes Dashboard installed, you can also use it to view resource usage across your cluster.

<figure><img src="/files/pL5Rn6vprU7bm58B3XTm" alt=""><figcaption><p>Example Nodes metrics from Home Lab K8s Cluster</p></figcaption></figure>
