天天看点

prometheus使用 (十七) alertmanager特性--静默

这个其实没啥说的,就是让告警静音,prometheus称这种警报静音为"silence"

比如我们有个业务要维护了,它一定会告警,那么我们可以设置一个时间段之后再告警

1. 页面静默

#我这里停止一台主机的node-exporter
systemctl stop node-exporter           
prometheus使用 (十七) alertmanager特性--静默
默认是静默2小时,看自己的使用情况。 之前出现过1天上万条告警,这样一来告警就没有意义了

2. 命令行静默

我们先手动将页面的静音取消

案例

#创建目录
mkdir /root/.config/amtool/ -p

#添加地址文件
cat > /root/.config/amtool/config.yml <<EOF
alertmanager.url: "http://192.168.1.20:9093"
author: [email protected]
comment_required: true
EOF


#添加静音
amtool silence add --comment "hello world" --duration "2h" alertname="node-up" instance="192.168.1.20:9100" job="node" severity="1" team="node"



#可以带多个标签来精准匹配
--comment "hello world"    #说明
--duration "2h"      #静音时间
 alertname="node-up" instance="192.168.1.20:9100" job="node" severity="1" team="node"
               #该告警的的标签           

返回

b067b3d9-a3b7-4eaf-9cfc-243234aa13fd           
prometheus使用 (十七) alertmanager特性--静默

常用命令

1. 查看已有的静音

amtool silence query           
ID                                    Matchers                                                                    Ends At                  Created By       Comment      
b067b3d9-a3b7-4eaf-9cfc-243234aa13fd  alertname=node-up instance=192.168.1.20:9100 job=node severity=1 team=node  2021-04-09 11:46:47 UTC  [email protected]  hello world             

2.指定silence过期

amtool silence expire b067b3d9-a3b7-4eaf-9cfc-243234aa13fd
#告警就又被启动了           

3.使用正则创建silence

amtool silence add --comment "App1 maintenance" alertname=~'.+'           

帮助命令

amtool silence --help           

继续阅读