如何从 Prometheus 绘制每日平均值

问题描述 投票:0回答:3

我必须根据 Prometheus 指标创建可视化。我有一个计数器指标

http_request_counter
,我想显示一天内服务的总请求的摘要。当我们使用石墨作为数据源时,我就是这样做的。

alias(summarize(sumSeries(consolidateBy(nonNegativeDerivative(http_request_counter.count), 'sum')), '1d', 'sum', false), 'TPS per day')

我看到了一些文档并尝试使用

increase(http_requests_total[24h])
绘制了带有
t-24h
值的图表。

有人可以帮我在普罗米修斯中找到相当于

summarize
的函数吗?

prometheus grafana promql
3个回答
6
投票

你需要

sum(increase(http_requests_total[24h]))
。它返回图表上每个点在“过去”24 小时内的请求摘要数量。默认情况下,Grafana 会从 Prometheus 查询许多点,以便根据图形的当前水平分辨率绘制平滑的图形。在 Grafana 中编辑图表时,可以使用 min step 选项调整图表上的点数。另一种选择是使用
subqueries
以及外部查询所需的步骤: last_over_time(sum(increase(http_requests_total[24h]))[1d:1d])

将以一日为步长返回连续线路。这些步骤将过去一天,例如当天的步骤将包含前一天发出的请求数。这种转变可以用负数来消除 
offset

:

last_over_time(sum(increase(http_requests_total[1d] offset -1d))[1d:1d])

不幸的是,这个查询在 Prometheus 中不能开箱即用,因为它默认不接受负偏移量。它们
在启动 Prometheus 时必须使用 --enable-feature=promql-negative-offset 命令行标志启用

。幸运的是,VictoriaMetrics(我工作的系统)中的MetricsQL默认支持负偏移量。


0
投票

avg_over_time( sum(rate(http_request_counter[5m])) by (method, some_other_label)[1d] )

由于它是一个计数器,因此您需要应用速率来获取每秒向量,然后在需要时使用 sum 来聚合某些标签上的多个系列,最后计算一天的平均值。


0
投票

© www.soinside.com 2019 - 2024. All rights reserved.