如何使用配置文件使Prometheus Alertmanager静音?

Edu*_*llo 6 kubernetes prometheus prometheus-operator prometheus-alertmanager

我使用的是官方的稳定/ prometheus-operator图表,确实使用头盔部署了Prometheus。

到目前为止,它运行良好,除了烦人的CPUThrottlingHigh警报正在触发许多Pod(包括自己的Prometheus的config-reloaders容器)。该警报当前正在讨论中,我现在暂时使其通知静音。

Alertmanager具有静音功能,但它是基于Web的:

静默是一种简单的方法,可以在给定时间内简单地使警报静音。在Alertmanager的Web界面中配置沉默。

有没有一种方法可以CPUThrottlingHigh使配置文件中的通知静音?

Edu*_*llo 7

好吧,我通过配置一个hackishhibin_rule使其得以正常工作:

inhibit_rules:
- target_match:
     alertname: 'CPUThrottlingHigh'
  source_match:
     alertname: 'DeadMansSwitch'
  equal: ['prometheus']
Run Code Online (Sandbox Code Playgroud)

根据DeadMansSwitch设计,这是普罗米修斯操作员附带的“始终触发”警报,并且该prometheus标签是所有警报的通用标签,因此CPUThrottlingHigh最终将永远被禁止使用。它发臭,但有效。

优点:

  • 这可以通过配置文件(使用alertmanager.confighelm参数)来完成。
  • CPUThrottlingHigh警报仍存在于Prometheus上以进行分析。
  • CPUThrottlingHigh警报如果“抑制的”复选框被选中在Alertmanager UI只显示了。
  • 我的接收器上没有烦人的通知。

缺点:

  • 标签上的任何更改DeadMansSwitchprometheus标签设计都会破坏此效果(仅表示再次触发警报)。

更新: 我的缺点变成了现实...

DeadMansSwitchaltertname 只是改变在稳定/普罗米修斯运营商4.0.0。如果使用此版本(或更高版本),则新的警报名称为Watchdog

  • 为了避免更改警报名称(“Watchdog”),您可以添加带有表达式“vector(1)”的记录规则,并在抑制配置中使用它。 (2认同)

cla*_*lay 6

一种选择是将您希望静音的警报路由到“空”接收器。在alertmanager.yaml

route:
  # Other settings...
  group_wait: 0s
  group_interval: 1m
  repeat_interval: 1h

  # Default receiver.
  receiver: "null"

  routes:
  # continue defaults to false, so the first match will end routing.
  - match:
      # This was previously named DeadMansSwitch
      alertname: Watchdog
    receiver: "null"
  - match:
      alertname: CPUThrottlingHigh
    receiver: "null"
  - receiver: "regular_alert_receiver"

receivers:
  - name: "null"
  - name: regular_alert_receiver
    <snip>
Run Code Online (Sandbox Code Playgroud)


Ali*_*ean 5

我怀疑是否存在通过配置使警报静音的方法(除了将所述警报路由到/dev/null接收器,即没有配置电子邮件或任何其他通知机制,但警报仍会显示在 Alertmanager UI 中)。

您显然可以使用alertmanager 附带的命令行工具amtool添加静音(尽管我看不到设置静音过期时间的方法)。

或者您可以直接使用 API(即使它没有记录并且理论上它可能会改变)。根据这个 prometheus-users 线程,这应该可以工作:

curl https://alertmanager/api/v1/silences -d '{
      "matchers": [
        {
          "name": "alername1",
          "value": ".*",
          "isRegex": true
        }
      ],
      "startsAt": "2018-10-25T22:12:33.533330795Z",
      "endsAt": "2018-10-25T23:11:44.603Z",
      "createdBy": "api",
      "comment": "Silence",
      "status": {
        "state": "active"
      }

}'
Run Code Online (Sandbox Code Playgroud)