PromQL to graph number of Kubernetes PODs created per Hour

9/26/2019

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

Now I'd like to Graph how many new PODs have been created per Hour over Time.

The Metric kube_pod_created 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:

count(rate(kube_pod_created[1h])) by(namespace)

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

-- powo
kube-state-metrics
kubernetes
prometheus
promql

1 Answer

9/26/2019

As per docs https://prometheus.io/docs/prometheus/latest/querying/functions/ rate() should be used with counters only. I suggest you use changes() function as time of creation value should change within your time frame in case of pod creation and maybe sum is better than count too.

changes()

For each input time series, changes(v range-vector) returns the number of times its value has changed within the provided time range as an instant vector.

sum(changes(kube_pod_created[1h])) by(namespace)

-- Child Detektiv
Source: StackOverflow