如何在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
相关产品推荐
相关产品推荐

