gpt4 book ai didi

Grafana PromQL: How do I get a Line graph of API Request Count?(Grafana PromQL:如何获得API请求计数的折线图?)

转载 作者:bug小助手 更新时间:2023-10-24 22:16:12 24 4
gpt4 key购买 nike



How do I get the actual count of the number of requests? and then have the curve return to 0 when there are no requests?

如何获得请求数的实际计数?然后在没有请求的情况下使曲线返回到0?


My current methods are either producing a cumulative sum or giving me a rate of requests per time interval.

我目前的方法要么是产生累计总和,要么是给我每个时间间隔的请求率。


The chosen type of graph is the time series.

选择的图表类型是时间序列。


The source of the data is AWS prometheus.

数据的来源是AWS普罗米修斯。


I have tried using this promQL query:

我已尝试使用此proQL查询:


api_request_count{}

Api_请求_计数{}


However; the curve doesn't return to zero when 0 requests have been made, see image below:

然而,当提出0个请求时,曲线不会归零,见下图:


result of using api_request_count{}


I have tried using the a rate query like such:
rate(api_request_count{}[$__rate_interval])

我尝试过这样使用速率查询:Rate(API_REQUEST_COUNT{}[$__RATE_INTERVAL])


But this gives me the rate at a given interval, see below:

但这给出了给定时间间隔的比率,如下所示:


result of using rate(api_request_count{}[$__rate_interval])


更多回答

In this case, you probably need query increase(api_request_count{}[$__rate_interval]). Please read about counters to gain some understanding what's going on.

在这种情况下,您可能需要查询increase(api_request_count{}[$__rate_interval]).请阅读有关计数器的内容,以了解发生了什么。

Also, be advised that increase not always returns integer values, even if you expect it to.

另外,需要注意的是,增量并不总是返回整数值,即使您希望它返回。

优秀答案推荐

There are some issues with Prometheus increase() data interpolation mentioned here.

这里提到的普罗米修斯增量()数据内插有一些问题。


My walkaround was to use rate() function with $__rate_interval as argument and multiply result by the interval($__interval_ms / 1000)

我使用的是rate()函数,参数为$__RATE_INTERVAL并将结果乘以间隔($__INTERVAL_MS/1000)


(sum(rate(http_server_duration_milliseconds_count{http_route=~"${Route}", http_method=~"${Method}"}[$__rate_interval])) by (http_route, http_method)) * $__interval_ms / 1000

for example:

例如:



  1. you are scraping data every 60 sec

  2. $__rate_interval is "guaranteed to be at least four times the scrape interval" (so it's 4min)

  3. We had 10 requests in (almost) one point in time, so the metrics shows change by 10 (from 1 to 11): enter image description hereenter image description here (query: http_server_duration_milliseconds_count{http_route="/actuator/health", http_method=~"GET"})

  4. rate query shows average rate in 3 points in timeenter image description here(query: rate(http_server_duration_milliseconds_count{http_route="/actuator/health", http_method=~"GET"}[$__rate_interval]))

  5. you multiply the results by $__interval_ms / 1000 and you receive number total number of requests (3 point with value of 3,33 requests)enter image description here (query: rate(http_server_duration_milliseconds_count{http_route="/actuator/health", http_method=~"GET"}[$__rate_interval]) * $__interval_ms / 1000)


I recommend using OpenTelemetry standards for Http metrics:
https://opentelemetry.io/docs/specs/otel/metrics/semantic_conventions/http-metrics/

我建议使用http指标的开放遥测标准:https://opentelemetry.io/docs/specs/otel/metrics/semantic_conventions/http-metrics/


If you decide to go with the standard, you can use predefined HTTP Dashboard prepared by me 👍
enter image description here

如果您决定使用该标准,您可以使用由Me👍准备的预定义HTTP Dashboard



Just use increase() over counter metric type:

只需使用计数器指标类型的增量()即可:


increase(api_request_count[$__rate_interval])

This query should return the number of API requests during the previous $__rate__interval ending at the current point on the graph. If the counter doesn't change during the previous interval, then the graph contains zero value at that point.

此查询应返回在图表上当前点结束的前$__RATE__间隔内的API请求数。如果计数器在前一个间隔内没有变化,则该图在该点包含零值。


Note that Prometheus may return unexpected results from increase() function because of the following issues described here:

请注意,由于此处描述的以下问题,Prometheus可能会从increase()函数返回意外结果:



  • it may return non-integer results from integer counters because of extrapolation

  • it skips counter increase between the last raw sample just before the $__rate_interval and the first raw sample inside the $__rate_interval


Prometheus developers are aware of these issues and are going to fix them eventually. See this design doc. In the mean time you can use an alternative Prometheus-like solution I work on, which is free from these issues.

普罗米修斯的开发者意识到了这些问题,并将最终解决这些问题。请参阅此设计文档。与此同时,你可以使用我正在研究的另一个类似普罗米修斯的解决方案,它没有这些问题。


更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com