具有Alert警报的AlertManager行为

时间:2018-07-17 15:12:14

标签: prometheus prometheus-alertmanager

我正在使用文本文件收集器导出到statistics.prom文件,该文件由update-statistics.sh脚本每分钟更新一次。这是.prom文件的示例。

item_has_stock{id="item.aaa", store="x"} 1
item_has_stock{id="item.aaa", store="y"} 1
item_has_stock{id="item.bbb", store="z"} 1
item_has_stock{id="item.ccc", store="k"} 1

每次update-statistics.sh运行时,库存值可能会从“ 1”更改为“ 0”,反之亦然。现在,说.prom文件已更新为:

item_has_stock{id="item.aaa", store="x"} 1
item_has_stock{id="item.aaa", store="y"} 0
item_has_stock{id="item.bbb", store="z"} 0
item_has_stock{id="item.ccc", store="k"} 0

Alertmanager,发送以下警报:

[FIRING:3] Item Stock
Item item.aaa at store y
Item item.bbb at store z
Item item.ccc at store k

在下一次运行update-statistics.sh时,item_has_stock {id =“ aaa”,store =“ y”}的值将从“ 0”更改为“ 1”,如下所示。

item_has_stock{id="item.aaa", store="x"} 1
item_has_stock{id="item.aaa", store="y"} 1
item_has_stock{id="item.bbb", store="z"} 0
item_has_stock{id="item.ccc", store="k"} 0

现在,alertmanager发送的警报如下:

[FIRING:2] Item Stock
Item item.aaa at store y
Item item.bbb at store z
Item item.ccc at store k

FIRING计数正确减少,但是“ y商店中的Item item.aaa”行不应再显示...这是alertmanager配置:

route:
  receiver: 'default'

  routes:
  - receiver: 'item-stock'
    group_by: ['item_has_stock']
    group_wait: 45s
    group_interval: 1m
    repeat_interval: 2m
    match_re:
      id: .*item.*

receivers:
  - name: 'default'
    slack_configs:
    - send_resolved: true
      api_url: '...'
      channel: '#channel'
      username: 'alertmanager'

  - name: 'item-stock'
    slack_configs:
    - send_resolved: true
      api_url: '...'
      channel: '#channel'
      username: 'alertmanager'
      title: '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] Item Stock'
      text: "{{ range .Alerts }}\nItem {{ .Labels.id }} at store {{ .Labels.store }}{{ end }}"

每3分钟触发一次的下一个FIRING警报(group_interval + repeat_interval)与上面的示例相同。仅在15分钟后(即5次提醒后),“ y商店中的item item.aaa”行最终消失。另外,我希望此行有已解决的警报...

PS:item-stock.rule文件包含表达式“ expr:item_has_stock == 0”,当值从“ 1”变为“ 0”时触发警报。

1 个答案:

答案 0 :(得分:2)

您设置了send_resolved: true,因此您的通知包含触发和已解决警报的组合,如[FIRING:2]所示,主体中包含三个警报。

您应该删除send_resolved: true

相关问题