首页 > 解决方案 > Prometheus 查询总和不适用于不同的事件

问题描述

我有这个命令的 hystrix 指标:

hystrix_execution_total

看起来像这样:

hystrix_execution_total{event="thread_pool_rejected", key="myapp"}
hystrix_execution_total{event="timeout", key="myapp"}
hystrix_execution_total{event="failure", key="myapp"}
hystrix_execution_total{event="success", key="myapp"}

它们都有一些价值。

我想从超时和失败中得到总和,但我遇到了问题。

hystrix_execution_total{event="timeout", key="myapp"} + hystrix_execution_total{event="failure", key="myapp"}

当我执行此操作时,我没有数据。

但是当我将事件更改为超时或失败时,我得到了总和。

那么为什么我不能得到不同事件的总和呢?

标签: grafanaprometheus

解决方案


这是因为 Prometheus 期望表达式两侧的标签匹配。你可以这样做:

hystrix_execution_total{event="timeout", key="myapp"} + ignoring(event) 
hystrix_execution_total{event="failure", key="myapp"}

推荐阅读