# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.farizizwan.com/devops-and-devsecops/kubernetes/fundamental/cluster-cpu-and-memory-inspections.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
