获取 Prometheus Alert 中的指标名称

发布于 2025-01-15 07:44:08 字数 272 浏览 6 评论 0原文

我正在设置一个 Prometheus 警报,它将针对多个指标发出警报。 它看起来像这样:

metric_x > threshold or metric_y > threshold or metric_x > threshold

但是如果此警报响起,我想在描述中包含有关哪个指标收到警报的内容。 有没有办法知道这 3 种情况中哪一种会导致警报响起?只是作为在警报描述中添加更多详细信息的一种方式吗? 唯一的方法是使用单独的警报或在描述中包含指标值吗?

I am setting up a Prometheus alert that will alert on several metrics.
It will look something like this:

metric_x > threshold or metric_y > threshold or metric_x > threshold

But if this alert goes off, I would like to include something in the description about which metric got alerted on.
Is there a way to know which one of those 3 conditions cause the alarm to go off? Just as a way to add more details in the alarm description?
Is the only way to do that is to have separate alarms or include the metric value in the description?

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

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

发布评论

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

评论(1

迷你仙 2025-01-22 07:44:08

底层的指标名称只是另一个标签,这意味着您可以将其插入注释中。方法如下:

- record: foo
  expr: 1
- record: bar
  expr: 2
- alert: test
  expr: foo == 1 or bar == 2
  # You probably need just one of these
  labels:
    name: '{{ .Labels.__name__ }}'
  annotations:
    name: '{{ .Labels.__name__ }}'

A metric name under the hood is just another label, which means you can insert it into an annotation. Here's how:

- record: foo
  expr: 1
- record: bar
  expr: 2
- alert: test
  expr: foo == 1 or bar == 2
  # You probably need just one of these
  labels:
    name: '{{ .Labels.__name__ }}'
  annotations:
    name: '{{ .Labels.__name__ }}'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文