我正在使用textfile收集器导出到statistics.prom文件,该文件每分钟由update-stattics.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 tics.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"} 0Alertmanager发送以下警报:
[FIRING:3] Item Stock
Item item.aaa at store y
Item item.bbb at store z
Item item.ccc at store k在下一次运行update-stattics.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触发计数正确地递减,但是"Item item.aaa at store y“这一行应该不再显示...以下是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分钟触发一次(group_interval + repeat_interval),看起来与上面的示例相同。仅在15分钟之后(即在5次警报之后),行"Item item.aaa at store y“终于消失了。另外,我希望这条线路有一个已解决的警报...
PS: item-stock.rule文件包含表达式"expr: item_has_stock == 0“,用于当值从"1”更改为"0“时触发警报。
https://stackoverflow.com/questions/51384876
复制相似问题