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

如何匹配仅在指定时间区间内符合条件的接口?

解决方案

要精准匹配最近2天内链路震荡后才新增"test"关键词的接口,需要同时满足三个核心条件:当前描述含"test"、2天前描述不含"test"、近2天内发生过链路状态切换。可以通过以下PromQL实现:

# 筛选当前描述带test的接口,排除2天前就带test的,再和链路震荡的接口取交集
interface_stats_oper_status{description=~".*test.*"}
unless
interface_stats_oper_status{description=~".*test.*"} offset 2d
and
# 链路震荡判断:近2天内状态切换次数大于1
changes(interface_stats_oper_status[2d]) > 1

如果需要统计符合条件的接口总数,用count函数包裹即可:

count(
  interface_stats_oper_status{description=~".*test.*"}
  unless
  interface_stats_oper_status{description=~".*test.*"} offset 2d
  and
  changes(interface_stats_oper_status[2d]) > 1
)

逻辑拆解

  • offset 2d:获取2天前的指标快照,用来排除原本就带有"test"的接口
  • changes():统计指定时间内指标值的变更次数,次数>1意味着链路状态频繁切换(震荡)
  • unless:取前一个集合减去后一个集合,得到"现在带test但2天前不带"的新增接口
  • and:最终保留同时满足"新增test"和"链路震荡"的目标接口

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 04:05:54