Prometheus 查询 promql 以在同一字段上取平均值

Prometheus query promql to make average on the same field

在我的 prometheus 数据库上,我有来自三个不同主机的指标,我想在它们之间取平均值,这样我就可以进行聚合:

information{application=~"$app",access=~"$access",quantile="0.99", host="prom01"}
information{application=~"$app",access=~"$access",quantile="0.99", host="prom02"}
information{application=~"$app",access=~"$access",quantile="0.99", host="prom03"}

我尝试在唯一的查询命令上将这三个指标相加并乘以三个,如下所示:

(information{application=~"$app",access=~"$access",quantile="0.99", host="prom01"} +
information{application=~"$app",access=~"$access",quantile="0.99", host="prom02"} +
information{application=~"$app",access=~"$access",quantile="0.99", host="prom03"})/3

但它不起作用<

另外,我试了sum+rate,也不行

sum by (host) (rate(information{application=~"$app",access=~"$access",quantile="0.99"})[5m])

您可以执行以下操作:

(scalar(information{application=~"$app",access=~"$access",quantile="0.99", host="prom01"}) +
 scalar(information{application=~"$app",access=~"$access",quantile="0.99", host="prom02"}) +
 scalar(information{application=~"$app",access=~"$access",quantile="0.99", host="prom03"})
) / 3

但如果你这样做会更容易:

(sum(information{application=~"$app",access=~"$access",quantile="0.99", host=~"prom0(1|2|3)"}))
) / 3

或者简单地说:

avg(information{application=~"$app",access=~"$access",quantile="0.99", host=~"prom0(1|2|3)"})