In my kubernetes cluster I have some running pods and a bunch of more pods in "completed" state. I use the query, for eg., kube_pod_container_resource_requests_cpu_cores{namespace="default"}
to get the cpu request of the pods in the default namespace. This gives me the cpu request off ALL pods. However, what I want is ONLY the cpu request of the pods in "Running" state. Any idea how to achieve this? Thanks
Please try with following query:
kube_pod_container_resource_requests_cpu_cores{job="kube-state-metrics"} * on (endpoint, instance, job, namespace, pod, service) group_left(phase) (kube_pod_status_phase{phase=~"^(Pending|Running)quot;} == 1)
which makes use of Prometheus matching operator to select labels that regex-match - here only Pods with Running or Pending state.