<p>I have kubernetes clusters with prometheus and grafana for monitoring and I am trying to build a dashboard panel that would display the number of pods that have been restarted in the period I am looking at.</p>
<p>Atm I have this query that fills a vector with 1 if the pod's creation time is  in the range (meaning it has been restarted during this period) and -1 otherwise.</p>
<p><code>-sgn((time() - kube_pod_created{cluster=&quot;$cluster&quot;}) - $__range_s)</code></p>
<p><a href="https://i.stack.imgur.com/j8BjL.png" rel="nofollow noreferrer">what this looks like</a></p>
<p>Is there a way to count the number of positive values in this vector and display it? Like in this example just have a box with red 1 inside.
Or maybe there is a better way to accomplish what I am trying.</p>

psilog
<p>To display the Pod Restarts we have different Prometheus metrics</p>
<p><code>kube_pod_container_status_restarts_total</code>. This is the counter metrics and this will record the container restarts.</p>
<p>To calculate the restarts:</p>
<ul>
<li>If you want to see all pods then,
<code>sum(increase(kube_pod_container_status_restarts_total{namespace=&quot;My-Namespace&quot;}[5m])) by(pod)</code></li>
<li>or If you want Particular Pod then use,
<code>sum(increase(kube_pod_container_status_restarts_total{namespace=&quot;My-Namespace&quot;, pod=&quot;My-Pod&quot;}[5m]))</code></li>
<li>or to show by container wise use
<code>sum(increase(kube_pod_container_status_restarts_total{namespace=&quot;My-Namespace&quot;, pod=&quot;My-Pod&quot;}[5m])) by(container)</code></li>
</ul>
