【发布时间】:2019-11-28 11:28:44
【问题描述】:
我有一个应用程序,它会在收到特定 HTTP 请求时增加 Prometheus 计数器。该应用程序在 Kubernetes 中运行,具有多个实例并每天重新部署多次。使用查询 http_requests_total{method="POST",path="/resource/aaa",statusClass="2XX"} 会按预期生成 graph displaying cumulative request counts per instance。
我想创建一个 Grafana 图表,显示过去 7 天收到的请求的累积频率。
我的第一个想法是使用increase(...[7d]) 来计算从 7 天窗口之外开始的任何指标(如图所示),然后使用 sum 这些值。
我意识到sum(increase(http_requests_total{method="POST",path="/resource/aaa",statusClass="2XX"}[7d])) 实际上确实给出了时间点的正确答案。但是,resulting graph isn't quite what was asked for 因为组件 increase(...) values increase/decrease along the week.
我将如何创建一个图表来显示过去 7 天内这些指标增加的累积总和?例如,给定以下简化数据
| Day | # Requests |
|-----|------------|
| 1 | 10 |
| 2 | 5 |
| 3 | 15 |
| 4 | 10 |
| 5 | 20 |
| 6 | 5 |
| 7 | 5 |
| 8 | 10 |
如果我要查看第 2 天到第 8 天的图表,我希望图表呈现如下线条,
| Day | Cumulative Requests |
|-----|---------------------|
| d0 | 0 |
| d1 | 5 |
| d2 | 20 |
| d3 | 30 |
| d4 | 50 |
| d5 | 55 |
| d6 | 60 |
| d7 | 70 |
其中d0表示图中的初始值
谢谢
【问题讨论】:
-
你有没有想出办法做到这一点?我正在尝试做同样的事情并且空无一物
-
恐怕我们没有
-
虽然这不能在 Prometheus 中完成,但可以使用 VictoriaMetrics 的 MetricsQL 轻松构建累积增量:
sum(remove_resets(http_requests_total) - range_first(http_requests_total))。 MetricsQL 还提供了running_sum()函数,可能对构建累积增长图很有用。
标签: grafana prometheus promql