You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Prometheus中基于另一指标标签过滤并排除特定实例?

可以实现,用PromQL就能搞定

你需要的效果可以通过PromQL的条件组合操作符来实现,以下是两种可行的写法:

方法一:使用unless操作符

unless会返回左边查询结果中,与右边指标标签(这里是hostname)不匹配的项,刚好可以用来排除存在指定process_cpu_usage指标的主机:

avg_over_time(system_cpu_usage[5m]) > 90
unless
process_cpu_usage{cpu_usage="high"}

方法二:使用absent函数

absent()函数会在指定指标不存在时返回1,存在时返回空值。结合and操作符,就能只保留没有process_cpu_usage{cpu_usage="high"}的主机:

avg_over_time(system_cpu_usage[5m]) > 90
and
absent(process_cpu_usage{cpu_usage="high"})

这两种写法都能达到你的需求:在system_cpu_usage5分钟平均超90的主机中,排除掉存在process_cpu_usage{cpu_usage="high"}的host2,最终只返回host3的结果。

内容的提问来源于stack exchange,提问作者Botch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 02:01:04