Prometheus queries to get CPU and Memory usage in kubernetes pods
17,046
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.
Author by
GihanS
Updated on June 13, 2022Comments
-
GihanS almost 2 years
I need to get CPU and Memory usage in kubernetes pods with prometheus queries. Can someone plz help?
-
GihanS about 5 yearsI want to have something like this "sum(container_memory_usage_bytes{namespace="$namespace", pod_name="$pod", container_name!="POD"}) by (container_name)" Since there are variables in this query Im unable to send alerts.
-
chaosguru about 3 yearswhy are you multiplying with 300