Prometheus 开启Alertmanager告警,设置企业微信为默认告警

Prometheus 开启Alertmanager告警

软件包下载

设置alertmanager.yml配置文件

配置文件具体信息如下

global:
  resolve_timeout: 5m
templates:
  - 'template/*.tmpl'          # 定义告警消息的通知模板

route:         # 路由策略
  group_by: ['alertname']       # 分组标签
  group_wait: 5s                # 告警等待时间,告警产生后等待5s,如果有同组告警一起发出
  group_interval: 1m            # 两组告警的间隔时间 
  repeat_interval: 3m           # 重复告警的时间间隔,减少相同邮件或者短信的发送频率,测试为3分钟
  receiver: 'webchat'           # 设置默认接受者
receivers:                      # 接受者信息
  - name: 'web.hook'            # 对应上面的receiver 接受者
    webhook_configs:
      - url: 'http://127.0.0.1:5010/'

  - name: 'webchat'
    wechat_configs:
      - send_resolved: true
        agent_id: 'xxxxx'             			# 企微自建应用的agent_id
        to_user: 'xxxxx'                 		# 接收告警信息的人员ID
        api_secret: 'xxxxx'         		 	# 自建应用的secret_id
        corp_id: 'xxxxxx'         				# 企业ID
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

prometheus设置alertmanager

配置prometheus.yml配置文件

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - alertmanager: 9093   # 开启alertmanager的9093

rule_files:     # 设置告警规则的路径信息
  - "/data/prometheus/alertmanager/rule/*.yml"

prometheus

告警消息通知模板

{{ define "wechat.default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 }}
========= 异常告警 =========
 触发时间: {{ ($alert.StartsAt.Add 28800e9).Format "2010-01-02 15:04:05" }}
 告警类型: {{ $alert.Labels.alertname }}
 告警级别: {{ $alert.Labels.severity }}
 告警详情: {{ $alert.Annotations.description}}     # 获取规则文件中的description
========= = end =  =========
{{- end }}
{{- end }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 }}
========= 告警恢复 =========
 告警类型: {{ $alert.Labels.alertname }}          # 获取规则文件中的alert
 告警级别: {{ $alert.Labels.severity }}           # 获取规则文件中的severity 
 触发时间: {{ ($alert.StartsAt.Add 28800e9).Format "2010-01-02 15:04:05" }} 
 恢复时间: {{ ($alert.EndsAt.Add 28800e9).Format "2010-01-02 15:04:05" }}
========= = end =  =========
{{- end }}
{{- end }}
{{- end }}
{{- end }}

启动

cd /data/prometheus/alertmanager
./amtool check-config alertmanager.yml   # 检查配置文件是否正确
  Checking 'alertmanager.yml'  SUCCESS
  Found:
   - global config
   - route
   - 1 inhibit rules
   - 2 receivers
   - 1 templates
    SUCCESS
nohup ./alertmanager --config.file=alertmanager.yml  --log.level=debug &  # 启动
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Richie-Hao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值