问题
I need to get CPU and Memory usage in kubernetes pods with prometheus queries. Can someone plz help?
回答1:
Do you use prometheus-operator to collect data from kubernetes? If yes, you can use something like this: sum(container_memory_usage_bytes) sum(container_cpu_usage_seconds_total) Just for example.
回答2:
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.
来源:https://stackoverflow.com/questions/55143656/prometheus-queries-to-get-cpu-and-memory-usage-in-kubernetes-pods