首页 > 解决方案 > 你可以在 promQL 查询中有多个聚合器吗

问题描述

在 influxQL 中,您可以使用多个聚合函数进行查询,如下所示:

SELECT MEAN(value), MIN(value) FROM measurement WHERE category= ...

在 promQl 中,您也可以指定聚合函数,例如 Avg:

Avg by (server) (HttpStatusCodes{category = 'Api.ResponseStatus'}) 

但我想知道您是否可以像在 influxQL 中一样在 promQl 中执行多个聚合器,如下所示:

Avg, Max by (server) (HttpStatusCodes{category = 'Api.ResponseStatus'}) 

标签: prometheusinfluxdbpromqlinfluxqlvictoriametrics

解决方案


尝试以下MetricSQL查询:

with (m = HttpStatusCodes{category = 'Api.ResponseStatus'})
(
  alias(max(max_over_time(m)) by (server),  "max"),
  alias(sum(sum_over_time(m)) by (server) / sum(count_over_time(m)) by (server), "avg")
)

推荐阅读