PromQL to graph number of Kubernetes PODs created per Hour

倾然丶 夕夏残阳落幕 提交于 2020-08-24 10:21:03

问题


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 ?


回答1:


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)



来源:https://stackoverflow.com/questions/58117048/promql-to-graph-number-of-kubernetes-pods-created-per-hour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!