promql表达式以两个间隔找到常见标签

发布于 2025-02-10 02:05:26 字数 343 浏览 2 评论 0 原文

可以说,我收集了以下指标,从现在-60m到30m -

fruits{name="apple"} 1
fruits{name="orange"} 1
fruits{name="pear"} 1

以及以下从现在到30m到现在收集的指标,

fruits{name="banana"} 1
fruits{name="pear"} 1
fruits{name="watermelon"} 1

我将如何编写一条警报规则,以检查两个集合中是否存在任何水果,并且它的名称是否存在?在这种情况下,将是

pear

Lets say i have the following metrics collected from now-60m to now-30m -

fruits{name="apple"} 1
fruits{name="orange"} 1
fruits{name="pear"} 1

and the following metrics collected from now-30m to now

fruits{name="banana"} 1
fruits{name="pear"} 1
fruits{name="watermelon"} 1

How would i go about writing an alert rule to check if any fruit is present in both collections and it's name? In this case it will be

pear

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2025-02-17 02:05:28

尝试以下查询:

count(last_over_time(fruits[30m] offset 30m)) by (name)
and
count(last_over_time(fruits[30m])) by (name)

它应返回 name 标签,这两个时间范围都存在 - (现在-60m ..现在-30m] (现在-30m) 现在]

  • .. 所有时间序列,在最后30分钟内存在
  • count 聚合函数
  • 运营商

Try the following query:

count(last_over_time(fruits[30m] offset 30m)) by (name)
and
count(last_over_time(fruits[30m])) by (name)

It should return name labels, which existed on both time ranges - (now-60m .. now-30m] and (now-30m .. now].

It uses the following functions:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文