问题描述
我想计算两个指标的比率,但没有数据...
我有一些指标,例如:
fs_bytes{filesystem="/var",instance="localhost:9108",job="graphite",metric="Used"} 50.0fs_bytes{filesystem="/var",instance="localhost:9108",job="graphite",metric="Total"} 100.0
当我尝试执行任何操作(设备、乘法、加法、减法)时:
fs_bytes{instance=localhost:9108",metric=Used"}/fs_bytes{instance=localhost:9108",metric=Total"}
普罗米修斯回来了:
没有数据
当我在 Prometheus 表达式浏览器中单独查询每个指标时,我确实得到了指标值.
怎么了?
当 prometheus 对表达式求值时,该操作隐式应用于共享相同标签集的指标.
尽管我指定了指标名称和大多数标签,但 Prometheus 一直在寻找具有相同标签集的指标.
但是,在这种情况下,两个指标具有不同的标签值,因此无法匹配!(一个指标具有 metric=Used"
,另一个指标具有 metric=Total"
.可能是其中一个指标具有一些额外的标签).>
解决方案是使用ignore
(或on
)来减少考虑的标签集:
fs_bytes{instance=localhost:9108",metric=Used"}/ignoring(metric) fs_bytes{instance=localhost:9108",metric=Total"}
阅读精美的手册!(此处)
I want to calculate a ratio of two metrics, but I get no data...
I have some metrics like:
fs_bytes{filesystem="/var",instance="localhost:9108",job="graphite",metric="Used"} 50.0
fs_bytes{filesystem="/var",instance="localhost:9108",job="graphite",metric="Total"} 100.0
When I try to do any operation (device, multiply, add, subtract) like:
fs_bytes{instance="localhost:9108",metric="Used"} / fs_bytes{instance="localhost:9108",metric="Total"}
Prometheus returned:
no data
When I query each metric alone in the Prometheus expression browser, I do get the metrics values.
What's wrong?
When prometheus is evaluating an expression, the operation implicitly apply to metric that share identical set of labels.
Despite the fact I specified the metric name and most labels, Prometheus was looking for metrics that have the same set of labels.
However, in this case, two metrics have different label values, so they can't match ! (one metric has metric="Used"
the other has metric="Total"
. It could be that one of the metrics has some extra labels).
The solution is to use ignore
(or on
) to reduce the set of considered labels:
fs_bytes{instance="localhost:9108",metric="Used"} / ignoring(metric) fs_bytes{instance="localhost:9108",metric="Total"}
Read the fine manual ! (here)
这篇关于Prometheus 在计算两个指标的比率时不返回任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!