Prometheus queries to get CPU and Memory usage in kubernetes pods

GihanS picture GihanS · Mar 13, 2019 · Viewed 10.2k times · Source

I need to get CPU and Memory usage in kubernetes pods with prometheus queries. Can someone plz help?

Answer

Tejas picture Tejas · Sep 9, 2020

For CPU percentage

avg((sum (rate (container_cpu_usage_seconds_total {container_name!="" ,pod="<Pod name>" } [5m])) by (namespace , pod, container ) / on (container , pod , namespace) ((kube_pod_container_resource_limits_cpu_cores >0)*300))*100)

For Memory percentage

avg((avg (container_memory_working_set_bytes{pod="<pod name>"}) by (container_name , pod ))/ on (container_name , pod)(avg (container_spec_memory_limit_bytes>0 ) by (container_name, pod))*100)

you can use above promql with pod name in a query.