【问题标题】:How to divide 2 metrics in Prometheus PromQL如何在 Prometheus PromQL 中划分 2 个指标
【发布时间】:2020-09-03 07:11:45
【问题描述】:

我正在使用 Prometheus 在 Graphana 中构建仪表板。 我有 2 个指标(对服务的总调用次数和总超时错误)

1 是对服务的总调用次数 PromQL-(增加(Fetching_RESPONSE_TIME_seconds_count{instance="${server}:8080"}[1h])

other 是总超时 PromQl-(增加(dp_errors_total{code=~"12345",instance="${server}:8080"}[1h]))

我想在我的仪表板中再增加一列,显示超时百分比,这将是(总超时*100/服务调用总数)。

当我这样做 PromQL- (increase(dp_errors_total{code=~"12345",instance="${server}:8080"}[1h])*100/(increase(Fetching_RESPONSE_TIME_seconds_count{instance="${server }:8080"}[1h])

它没有在我的仪表板上显示任何内容。

如何在我的仪表板中再添加一列来显示超时百分比?

【问题讨论】:

    标签: prometheus grafana prometheus-alertmanager promql prometheus-operator


    【解决方案1】:

    当您尝试执行算术表达式时,Prometheus 将尝试在左侧和右侧匹配时间序列。它通过他们拥有的标签来做到这一点。双方必须有相同的标签(名称和值)。 我不知道您的时间序列具有的所有标签,但我可以猜测,例如 code 标签仅出现在 dp_errors_total 上,而不出现在第二个标签上。 我通常会先聚合两个操作数(根据需要),例如:

    sum by (server) ( ... dp_errors_total query ) 
    /
    sum by (server) ( ... Fetching_RESPONSE_TIME_seconds_count query ...)
    

    或者如果$server 中只有一台服务器,则删除by (server) 部分。

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 2017-12-13
      • 2021-11-13
      • 2020-06-29
      • 1970-01-01
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      相关资源
      最近更新 更多