Kubernetes CPU Memory Usage in %

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

Hi Team,
Can someone suggest?