简体   繁体   English

如何在 grafana 图表中计算和显示计数器的值变化

[英]How to calculate and show the value of counter as it changed in grafana chart

I have a counter metric upgrade_counter which is incremented every time an upgrade happens.我有一个计数器指标upgrade_counter ,每次升级时它都会递增。 I want to show up a chart in grafana which will tell how many upgrades we have got in last 7 days.我想在 grafana 中显示一个图表,它会告诉我们在过去 7 天内获得了多少次升级。 I want to show a progression as how the num of upgrades increased over the last 7 days.我想展示过去 7 天内升级数量增加的进展情况。

I have used following query and it does not correctly show how many upgrades we have received.我使用了以下查询,但它没有正确显示我们收到了多少升级。

sum(increase(upgrade_counter{}[7d]))

Value reported in chart is around 40 - 50% lower.图表中报告的值大约低 40 - 50%。

Prometheus may return unexpected results from increase() function because of extrapolation - see this issue .由于外推,Prometheus 可能会从increase() function 返回意外结果 - 请参阅此问题 I'd suggest trying VictoriaMetrics instead - it returns the expected results from increase() function.我建议改用VictoriaMetrics - 它返回increase() function 的预期结果。

Note that the PromQL query is executed independently per each point on the graph in Grafana.请注意,PromQL 查询是针对 Grafana 中图表上的每个点独立执行的。 So every point on the graph for increase(upgrade_counter[7d]) query would contain the number of upgrades during the last 7 days ending at that particular point.因此, increase(upgrade_counter[7d])查询图表上的每个点都将包含在该特定点结束的过去 7 天内的升级次数。 If you need obtaining a cumulative graph, which starts from zero and increases over time with the number of upgrades on the selected time range, then try the following MetricsQL query:如果您需要获取累积图,该图从零开始,随着时间的推移随着所选时间范围内的升级次数增加,请尝试以下MetricsQL查询:

running_sum(increase(upgrade_counter))

This query works only in VictoriaMetrics, and it doesn't work in Prometheus, because it uses the following MetricsQL features:此查询仅在 VictoriaMetrics 中有效,在 Prometheus 中无效,因为它使用了以下 MetricsQL 功能:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM