<p>I am using Prometheus and Grafana to collect and display pod/container status for a Kubernetes cluster. I'm collecting the information from the following metrics:</p>
<pre><code>kube_pod_container_status_running
kube_pod_container_status_terminated
kube_pod_container_status_waiting
</code></pre>
<p><strong>Note</strong>: I left a fourth metric, <code>kube_pod_container_status_ready</code> out as it seems to be a duplicate of <code>kube_pod_container_status_running</code>. If I am mistaken, please let me know what the difference is.</p>
<p>Each metric returns a 0 or 1 result, where 1 indicates the container is currently in that state (e.g. runnning). I'm making the assumption that at any given time, only one of these metrics should have a value of 1 for a given set of labels representing a specific container in the cluster. From what I've seen, each metric collects the same set of label dimensions.</p>
<p>What I would like to do is display a table of container information of interest (pod, container, namespace, etc.) plus a column indicating the current state (Running, Terminated, etc.). I may need to include other queries to integrate other information not available from this current set.</p>
<p>I have tried a couple of experiments that have allowed me to collect the information into a single table view, but cannot figure out how to translate the 3 metric results into a single state representation. So, for example: [running=1, terminated=0, waiting=0] into &quot;Running&quot;, or [running=0, terminated=0, waiting=1] into &quot;Waiting&quot;.</p>
<p>Any help on this would be appreciated.</p>

Joseph Gagnon
<p>You metrics seems rather strange, and even against Prometheus' recommendations.
Usually such metrics would be in format <code>kube_pod_container_status{status=&quot;waiting&quot;}</code>.</p>
<p>You can convert your metrics to conventional format, and display them in table.</p>
<p>Use query</p>
<pre><code>label_replace(
 label_replace(
  {__name__=~&quot;kube_pod_container_status_.*&quot;} == 1
  ,&quot;status&quot;,&quot;$1&quot;,&quot;__name__&quot;,&quot;kube_pod_container_status_(.*)&quot;)
,&quot;__name__&quot;,&quot;kube_pod_container_status&quot;,&quot;__name__&quot;,&quot;.*&quot;)
</code></pre>
<p>And switch <a href="https://grafana.com/docs/grafana/latest/datasources/prometheus/query-editor/#format" rel="nofollow noreferrer">format</a> of you query (under your query editor) to &quot;Table&quot;.</p>
<p>If you'll use panel &quot;Table&quot;, you'll see metrics like you described.</p>
