# Kubernetes CPU Memory Usage in %

**URL:** <https://discuss.elastic.co/t/kubernetes-cpu-memory-usage-in/322429>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [January 4, 2023, 7:34am UTC](https://discuss.elastic.co/t/kubernetes-cpu-memory-usage-in/322429 "2023-01-04T07:34:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankita\_Pachauri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankita_pachauri/32/61469_2.png) [@Ankita\_Pachauri](https://discuss.elastic.co/u/Ankita_Pachauri)\
**Post date:** [January 4, 2023, 7:34am UTC](https://discuss.elastic.co/t/kubernetes-cpu-memory-usage-in/322429/1 "2023-01-04T07:34:03Z")

</div>

Hi Team,  
We need to find the CPU and Memory utilization % of pods in kubernetes through metricbeat.  
I have used the formula as:  
CPU:

> {  
> "aggs": {  
> "timeseries": {  
> "auto\_date\_histogram": {"field": "@timestamp", "buckets": "1"},  
> "aggs": {  
> "hosts": {  
> "terms": {"field": "kubernetes.pod.name.keyword", "size": 1000},  
> "aggs": {  
> "usage": {"avg": {"field": "kubernetes.container.cpu.usage.nanocores"}},  
> "transform": {  
> "bucket\_script": {  
> "buckets\_path": {"nano": "usage"},  
> "script": {  
> "source": "Math.round((params.nano/1000000000)\*100)",  
> "lang": "painless"  
> }  
> }  
> }

Memory:

> {  
> "aggs": {  
> "timeseries": {  
> "auto\_date\_histogram": {"field": "@timestamp", "buckets": "1"},  
> "aggs": {  
> "hosts": {  
> "terms": {"field": "kubernetes.pod.name.keyword", "size": 100},  
> "aggs": {  
> "usage": {"avg": {"field": "kubernetes.container.memory.usage.bytes"}},  
> "total": {  
> "avg": {  
> "field": "kubernetes.container.memory.limit.bytes"  
> }  
> },  
> "transform": {  
> "bucket\_script": {  
> "buckets\_path": {"nano": "usage", "core": "total"},  
> "script": {  
> "source": "Math.round((params.nano/params.core)\*100)",  
> "lang": "painless"  
> }  
> }  
> }

If we use the below fields then there is a huge difference in the values:

| **CPU Usage** | Average of `kubernetes.pod.cpu.usage.node.pct`. |
| --- | --- |
| **Memory Usage** | Average of `kubernetes.pod.memory.usage.node.pct`. |

I would like to understand that which fields are correct for getting utilization in %.

Please support.

//Ankita

---

<div class="post-metadata">

**Author:** ![Ankita\_Pachauri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankita_pachauri/32/61469_2.png) [@Ankita\_Pachauri](https://discuss.elastic.co/u/Ankita_Pachauri)\
**Post date:** [January 9, 2023, 4:08am UTC](https://discuss.elastic.co/t/kubernetes-cpu-memory-usage-in/322429/2 "2023-01-09T04:08:56Z")

</div>

Hi Team,  
Can someone suggest?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 6, 2023, 4:09am UTC](https://discuss.elastic.co/t/kubernetes-cpu-memory-usage-in/322429/3 "2023-02-06T04:09:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
