<p>In my kubernetes cluster I have some running pods and a bunch of more pods in "completed" state. I use the query, for eg.,
<code>kube_pod_container_resource_requests_cpu_cores{namespace="default"}</code> 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</p>

Mulugeta Ayalew Tamiru
<p>Please try with following query:</p>
<pre><code>kube_pod_container_resource_requests_cpu_cores{job=&quot;kube-state-metrics&quot;} * on (endpoint, instance, job, namespace, pod, service) group_left(phase) (kube_pod_status_phase{phase=~&quot;^(Pending|Running)$&quot;} == 1)
</code></pre>
<p>which makes use of <a href="https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching" rel="nofollow noreferrer">Prometheus matching operator</a> to select labels with regex-match - here only Pods with Running or Pending state.</p>
