本文介绍了PromQL以图表形式显示每小时创建的Kubernetes POD数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有kube-state-metrics和Prometheus/grafana的Kubernetes来绘制Kubernetes集群的各种指标.

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

现在,我想用图表显示每小时随时间创建的个POD.

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

度量标准kube_pod_created包含创建时间戳记作为值,但是由于每个时隙中都有一个值,因此以下查询还为未创建新POD的时隙返回结果> 0.

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)

我可以在某种条件下使用Value来仅计算Value是否在当前"时隙内吗?

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

推荐答案

根据docs https://prometheus.io/docs/prometheus/latest/querying/functions/ rate()应该仅与计数器一起使用.我建议您使用changes()函数,因为在创建pod的情况下,创建时间应该在您的时间范围内更改,并且总和也可能比计数更好.

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(v range-vector)将其值在提供的时间范围内变化的次数作为即时向量返回.

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)

这篇关于PromQL以图表形式显示每小时创建的Kubernetes POD数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:54