资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

prometheusAlertManager微信报警配置

准备工作:

创新互联是一家专业提供瓜州企业网站建设,专注与成都网站设计、成都网站建设、H5建站、小程序制作等业务。10年已为瓜州众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

获取企业×××的对外接口

企业×××的secret_api

企业信息ID corp_id

wechat_api_url: wechat对外接口https://qyapi.weixin.qq.com/cgi-bin/
wechat_×××: 企业×××("企业应用"-->"自定应用"[Prometheus]--> "Secret") Prometheus是本人自创建应用名称
wechat_api_corp_id: 企业信息("我的企业"--->"CorpID"[在底部])
to_party: 1值是组的ID 你可通过链接去定制报警信息接收人或者组(https://work.weixin.qq.com/ap...
agent_id: 企业×××("企业应用"-->"自定应用"[Prometheus]--> "AgentId") Prometheus是本人自创建应用名称

如果prometheus和alertmanager的配置文件是分开(不是helm安装)

Prometheus中AlertManager配置:

alerting 与 global同级

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093

rules配置文件加入到Prometheus配置文件中

rule_files:
- "/usr/local/prometheus/rules.yml"

prometheus rules配置
创建rule.yml文件
根据需求添加报警规则
groups:
- name: prometheus_go_goroutines
rules:
- alert: go_goroutines_numbers
expr: go_goroutines > 45
for: 15s
annotations:
summary: "prometheus的gorotine数据超过40!"

Prometheus AlertManager配置
alertmanager 配置文件,加入×××配置信息
global:
resolve_timeout: 2m
wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
wechat_×××: 'xxx'
wechat_api_corp_id: 'xxx'

route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'wechat'
receivers:
- name: 'wechat'
wechat_configs:
- send_resolved: true
to_party: '1'
agent_id: '1000002'

===================================================================

如果是用helm安装的,那么我们的promethues和alertmanager的配置是在一个文件中的

vim  prometheus-operator-custom.yaml   # 修改配置

alertmanager: 下配置
config:
global:
# 每2分钟检查一次是否恢复
resolve_timeout: 3m
templates:
- '/etc/alertmanager/config/template_wechat.tmpl'
route:
# 将传入的报警中有这些标签的分为一个组.
group_by: ['wechat_alert']
# 指分组创建多久后才可以发送压缩的警报,也就是初次发警报的延时.
# # 这样会确保第一次通知的时候, 有更多的报警被压缩在一起.
group_wait: 15s
# 当第一个通知发送,等待多久发送压缩的警报
group_interval: 15s
# 如果报警发送成功, 等待多久重新发送一次
repeat_interval: 3m
receiver: 'wechat'
routes:
- receiver: 'wechat'
continue: true
receivers:
- name: 'wechat'
wechat_configs:
# 是否发送恢复告警
- send_resolved: true
# ×××公众号ID
corp_id: 'XXX'
# ×××应用密钥
×××: 'XXX'
# 可发送的用户名 可以多个 
#to_user: '@all'
# 部门ID 点击部门的时候 右下角的弹窗可以看到 比较隐蔽
to_party: '92'
agent_id: '1000010'
# 模板格式:
templateFiles:
template_wechat.tmpl: |-
{{ define "wechat.default.message" }}
{{ range .Alerts }}
=====start======
告警程序: k8s_prometheus_alert
告警级别: {{ .Labels.severity }}
告警类型: {{ .Labels.alertname }}
故障主机: {{ .Labels.name }}
告警阈值: {{ .Annotations.value }}
告警主题: {{ .Annotations.summary }}
# 时间默认UTC 所以后边加入28800e9 也就是多了啦8个小时 
触发时间: {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
======end======
{{ end }}
{{ end }}

报警规则配置文件:
helm安装配合文件合并,所以报警规则独立出一个文件,加载时多加载一个文件即可。

vim  rules-custom.yaml  # 编辑规则文件


additionalPrometheusRules:
- name: cpu1
groups:
- name: cpu load
rules:
- alert: pod cpu 超过1%
expr: (sum by(name)(rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 30
for: 1m
labels:
severity: critical
annotations:
value: "{{ $value }}"
description: The configuration of the instances of the Alertmanager cluster`{{$labels.service}}` are out of sync.
summary: "这是第一个组的第一个测试 OK"
# - alert: pod memcache 超过1%
# expr: (sum by(name)(rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 5
# for: 5m
# labels:
# severity: critical
# annotations:
# description: An unexpected number of Alertmanagers are scraped or Alertmanagers disappeared from discovery.
# summary: "这是第一个组的第二个测试"
- name: cpu2
groups:
- name: node load
rules:
- alert: 另一个group pod 超过 1%
expr: (sum by(name)(rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 30
for: 1m
labels:
severity: critical
annotations:
value: "{{ $value }}"
summary: "这是第二个组的测试 ok"

最后我们在加载的时候只需多加载一个配置文件:

可同时加载两个配置:
helm upgrade monitoring stable/prometheus-operator --version=5.0.3 --namespace=monitoring -f prometheus-operator-custom.yaml -f rules-custom.yaml


新闻标题:prometheusAlertManager微信报警配置
本文来源:http://cdkjz.cn/article/pgisep.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220