Prometheus 查询总和不适用于不同的事件

Prometheus query sum not working for different event

我有这个命令的 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"}

当我执行这个时,我没有数据。

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

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

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

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