【问题标题】:Grafana variable - Interval mutiplierGrafana 变量 - 区间乘数
【发布时间】:2020-06-10 05:02:46
【问题描述】:

我在 grafana 中绘制了一个图表,其中我得到了一个计数器的速率并从另一个计数器的速率中减去它。 我在图中使用区间变量。 现在,当我想使用 5m 作为间隔时,我希望将速率乘以 (5*60)。 同样当 1h 那么它应该乘以 (1 * 24 * 60 * 60)

$period = 1m,5m,10m,1h and like this.

我的查询

rate(service_total{state="otp_send"}[$period]) * 300 - ignoring(state) rate(service_total{state="otp_validate"}[$period]) *300 

所以我希望将这 300 放入一个变量中,当我更改 grafana 中的 $period 值时该变量会发生变化

> If $period is 5m, 300 should be 300 
> If $period is 1m, 300 should be 60
> If $period is 10m, 300 should be 600

以这种方式。 有什么我可以在 grafana 中做的。

所以基本上我想将 $period 附加到一个根据间隔相乘的常量变量。

【问题讨论】:

    标签: prometheus grafana grafana-variable


    【解决方案1】:
      increase(service_total{state="otp_send"}[$period]) 
    - ignoring(state) 
      increase(service_total{state="otp_validate"}[$period]) 
    

    increase 是 rate 之上的语法糖,它可以做到这一点。

    【讨论】:

      【解决方案2】:

      您可以将“rate(vector)*time”更改为“delta(vector)”以获得相同的结果,如下所示:

      delta(service_total{state="otp_send"}[$period]) - ignoring(state) delta(service_total{state="otp_validate"}[$period])
      

      Prometheus 文档here 中的更多信息。

      更新:

      正如@brian-brazil 回答的那样,在这种情况下正确的是使用“increase”函数而不是“delta”函数,因为第二个函数不处理计数器重置。

      Prometheus 文档here中的更多信息

      【讨论】:

      • 将delta 与计数器一起使用是不正确的,并且通常它不是您通常希望使用deriv 或increase 的函数。
      • 当与计数器一起使用时,我看不出“delta”和“increase”之间的区别。你能解释一下区别吗?
      • Delta 不处理计数器重置,因为它是为仪表设计的。
      • 好的,谢谢。您认为删除答案以免混淆人会更好吗?
      • 这取决于你,也许是一个编辑来说明它为什么不正确?这不是一个罕见的错误。
      猜你喜欢
      • 2021-12-09
      • 1970-01-01
      • 2019-05-02
      • 2019-10-05
      • 2020-01-19
      • 2022-11-30
      • 1970-01-01
      • 2021-12-26
      • 2021-11-29
      相关资源
      最近更新 更多