问题描述
我需要在Grafana中显示一个面板,其中在右上角选择的时间段内的请求数.
I need to show, in Grafana, a panel with the number of requests in the period of time selected in the upper right corner.
为此,我需要在这里解决2个问题,我将在此处询问普罗米修斯问题,并在另一个链接中询问Grafana问题.
For this I need to solve 2 issues here, I will ask the prometheus question here and the Grafana question in another link.
如果我有一个计数器http_requests_total
,如何构建查询以获取一段时间内(例如:24hs)请求总数的整数?
If I have a Counter http_requests_total
, How can I build a query to get an integer with the total number of requests during a period of time (for example:24hs)?
推荐答案
您需要的是 increase()函数,该函数将计算指定时间间隔的开始和结束时计数器值之间的差.它还可以正确处理该时间段内的计数器重置(如果有).
What you need is the increase() function, that will calculate the difference between the counter values at the start and at the end of the specified time interval. It also correctly handles counter resets during that time period (if any).
increase(http_requests_total[24h])
如果您有多个计数器http_requests_total
(例如来自多个实例),并且需要获取请求的累积计数,请使用 sum()运算符:
If you have multiple counters http_requests_total
(e.g. from multiple instances) and you need to get the cumulative count of requests, use the sum() operator:
sum(increase(http_requests_total[24h]))
另请参阅我的答案关于在查询中使用Grafana的时间范围选择的那部分问题.
See also my answer to that part of the question about using Grafana's time range selection in queries.
这篇关于在一段时间内获取总计请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!