<p>I'm using Kubernetes with kube-state-metrics and Prometheus/grafana to graph various metrics of the Kubernetes Cluster.</p>

<p>Now I'd like to Graph how many <strong>new</strong> PODs have been created per Hour over Time.</p>

<p>The Metric <code>kube_pod_created</code> contains the Creation-Timestamp as Value but since there is a Value in each Time-Slot, the following Query also returns Results >0 for Time-Slots where no new PODs have been created:</p>

<pre><code>count(rate(kube_pod_created[1h])) by(namespace)
</code></pre>

<p>Can I use the Value in some sort of criteria to only count if Value is within the "current" Time-Slot ?</p>

powo
<p>The following query returns the number of pods created during the last hour:</p>
<pre><code>count(last_over_time(kube_pod_created[1h]) &gt; time() - 3600)
</code></pre>
<p>How does it work?</p>
<p>The <code>last_over_time(kube_pod_created[1h])</code> returns creation timestamps for pods, which were active during the last hour (see <a href="https://docs.victoriametrics.com/MetricsQL.html#last_over_time" rel="nofollow noreferrer">last_over_time()</a> docs). This includes pods, which could be started long time ago and are still active alongside pods, which where created during the last hour.</p>
<p>We need to filter out pods, which were created more than a hour ago. This is performed by comparing pod creation timestamps to <code>time() - 3600</code> (see <a href="https://docs.victoriametrics.com/MetricsQL.html#time" rel="nofollow noreferrer">time()</a> docs). Such comparison removes time series for pods created more than a hour ago. See <a href="https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators" rel="nofollow noreferrer">these docs</a> for details on how doe comparison operators work in PromQL.</p>
<p>Then the outer <a href="https://docs.victoriametrics.com/MetricsQL.html#count" rel="nofollow noreferrer">count()</a> returns the number of time series, which equals to the number of pods created during the last hour.</p>
