每分钟 PromQL 请求数

PromQL Requests per minute

我正在尝试在图表中创建每分钟总 POST 请求的图表,但是这种 "ramp up" 模式让我相信我没有得到实际总数每分钟的请求数,但得到一个累积值。

这是我的查询:

sum_over_time(django_http_responses_total_by_status_view_method_total{job="django-prod-app", method="POST", view="twitch_webhooks"}[1m])

这是 7 天内的 "ramp up" 模式(下降表示重新启动):

让我相信我对 sum_over_time() 的理解是不正确的,因为现有的 webhook 应该始终存在。在最近一次重启时,我们有 72k 的 webhook 订阅,因此随着时间的推移该值攀升是没有意义的,在开始时看到一个大的尖峰用于捕获未捕获的 webhook 会更有意义在停机期间。

此查询是否适合我要实现的目标?

我正在使用 django-prometheus 进行导出。

你想要 increase 而不是 sum_over_time,因为这是一个计数器。

如果 django_http_responses_total_by_status_view_method_total 指标是 counter, then increase() 函数,则必须用于 return 最后一分钟的请求数:

increase(django_http_responses_total_by_status_view_method_total[1m])

请注意,即使 django_http_responses_total_by_status_view_method_total 指标仅包含整数值,Prometheus 中的 increase() 函数也可以 return 小数结果。这是由于实现细节所致 - 请参阅 this comment and this article 了解详细信息。

如果 django_http_responses_total_by_status_view_method_total 指标是一个 gauge, which shows the number of requests since the previous sample, then sum_over_time() 函数必须用于每最后一分钟 returning 请求:

sum_over_time(django_http_responses_total_by_status_view_method_total[1m])