<p>I'm trying to calculate the average time a pod stays in a pending state in grafana with prometheus. I can generate a graph to get the number of pods in a pending state over time, with this query</p>

<pre><code>sum(kube_pod_status_phase{phase="Pending"})
</code></pre>

<p>However, I would really like to get an the value of the average time that the pods are staying in this state in the last X hours. How can I do that?</p>

Bruno_Ferreira
<p>The metric <code>kube_pod_status_phase{phase=&quot;Pending&quot;}</code> will only give you binary values i.e., 0/1.
1 if the pod is in pending state, 0 otherwise.
Also, the data is being updated every 30s.
So to find the total time it was in pending in last X hours, you can do something like.</p>
<pre><code>sum_over_time(kube_pod_status_phase{phase=&quot;Running&quot;}[Xh]) * X * 30
</code></pre>
<p>For better visualization, you can use table in grafana.</p>
