如何在alertmanager报警中添加企业微信监控报警-创新互联
Prometheus机器:172.27.143.155
alertmanager机器:172.27.143.150
Prometheus 告警分为两部分。Prometheus 服务器中的告警规则会向Alertmanager发送告警。
然后,Alertmanager 处理这些告警信息,包括沉默,禁止,聚合和发送到电子邮件、PagerDuty和HipChat等。
设置告警和通知的主要步骤是:
设置并配置Alertmanager
配置Prometheus和Alertmanager通信
在Prometheus中创建告警规则
Alertmanager处理客户端应用程序(如Prometheus服务器)发送的警报。
它负责重复数据删除,分组并将它们路由到正确的接收方集成,例如电子邮件,PagerDuty或OpsGenie。 它还处理警报的沉默和抑制。
一、上面配置了Prometheus和grafana服务在155机器上面
接下来配置 alermanager服务
1、wget https://github.com/prometheus/alertmanager/releases/download/v0.20.0/alertmanager-0.20.0.linux-amd64.tar.gz
2、tar zxf alertmanager-0.20.0.linux-amd64.tar.gz
3、mv alertmanager-0.20.0.linux-amd64 /usr/local/alertmanager
4、vim alertmanager.yml
5、vim /etc/alertmanager/template/wechat.tmpl
{{ define "wechat.default.message" }}
{{ range $i, $alert :=.Alerts }}
========监控报警==========
告警状态:{{ .Status }}
告警级别:{{ $alert.Labels.severity }}
告警类型:{{ $alert.Labels.alertname }}
告警应用:{{ $alert.Annotations.summary }}
告警主机:{{ $alert.Labels.instance }}
告警详情:{{ $alert.Annotations.description }}
触发阀值:{{ $alert.Annotations.value }}
告警时间:{{ $alert.StartsAt.Format "2006-01-02 15:04:05" }}
========end==========
{{ end }}
{{ end }}
6、完成之后启动服务
nohup ./alertmanager &
接下来配置Prometheus服务
修改配置文件
需要创建一个 rules目录
里面又2个文件,一个时主机监控,一个时容器监控
1)cat host_sys.yml
groups:
- name: Host
rules:- alert: Memory Usage
expr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes)) / node_memory_MemTotal_bytes * 100 > 2
for: 1m
labels:
name: Memory
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: "宿主机内存使用率超过80%."
value: "{{ $value }}" - alert: CPU Usage
expr: sum(avg without (cpu)(irate(node_cpu_seconds_total{mode!='idle'}[5m]))) by (instance,appname) > 0.05
for: 1m
labels:
name: CPU
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: "宿主机CPU使用率超过65%."
value: "{{ $value }}" - alert: HostLoad
expr: node_load5 > 4
for: 1m
labels:
name: Load
severity: Warning
annotations:
summary: "{{ $labels.appname }} "
description: " 主机负载5分钟超过4."
value: "{{ $value }}" - alert: Filesystem Usage
expr: 1-(node_filesystem_free_bytes / node_filesystem_size_bytes) > 0.3
for: 1m
labels:
name: Disk
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: " 宿主机 [ {{ $labels.mountpoint }} ]分区使用超过80%."
value: "{{ $value }}%" - alert: Diskio writes
expr: irate(node_disk_writes_completed_total{job=~"Host"}[1m]) > 50
for: 1m
labels:
name: Diskio
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: " 宿主机 [{{ $labels.device }}]磁盘1分钟平均写入IO负载较高."
value: "{{ $value }}iops" - alert: Diskio reads
expr: irate(node_disk_reads_completed_total{job=~"Host"}[1m]) > 5
for: 1m
labels:
name: Diskio
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: " 宿主机 [{{ $labels.device }}]磁盘1分钟平均读取IO负载较高."
value: "{{ $value }}iops" - alert: Network_receive
expr: irate(node_network_receive_bytes_total{device!~"lo|bond[0-9]|cbr[0-9]|veth.|virbr.|ovs-system"}[5m]) / 1048576 > 5
for: 1m
labels:
name: Network_receive
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: " 宿主机 [{{ $labels.device }}] 网卡5分钟平均接收流量超过5Mbps."
value: "{{ $value }}Mbps" - alert: Network_transmit
expr: irate(node_network_transmit_bytes_total{device!~"lo|bond[0-9]|cbr[0-9]|veth.|virbr.|ovs-system"}[5m]) / 1048576 > 5
for: 1m
labels:
name: Network_transmit
severity: Warning
annotations:
summary: " {{ $labels.appname }} "
description: " 宿主机 [{{ $labels.device }}] 网卡5分钟内平均发送流量超过5Mbps."
value: "{{ $value }}Mbps"
- alert: Memory Usage
2) cat container_sys.yml
groups:
- name: Container
rules:- alert: CPU Usage
expr: (sum by(name,instance) (rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 80
for: 1m
labels:
name: CPU
severity: Warning
annotations:
summary: "{{ $labels.name }} "
description: " 容器CPU使用超过80%"
value: "{{ $value }}%" - alert: Memory Usage
expr: (container_memory_usage_bytes{name=~".+"} - container_memory_cache{name=~".+"}) / container_spec_memory_limit_bytes{name=~".+"} * 100 > 80
for: 1m
labels:
name: Memory
severity: Warning
annotations:
summary: "{{ $labels.name }} "
description: " 容器内存使用超过80%."
value: "{{ $value }}%" - alert: Network_receive
expr: irate(container_network_receive_bytes_total{name=~".+",interface=~"eth.+"}[5m]) / 1048576 > 5
for: 1m
labels:
name: Network_receive
severity: Warning
annotations:
summary: "{{ $labels.name }} "
description: "容器 [{{ $labels.device }}] 网卡5分钟平均接收流量超过5Mbps."
value: "{{ $value }}Mbps" - alert: Network_transmit
expr: irate(container_network_transmit_bytes_total{name=~".+",interface=~"eth.+"}[5m]) / 1048576 > 5
for: 1m
labels:
name: Network_transmit
severity: Warning
annotations:
summary: "{{ $labels.name }} "
description: "容器 [{{ $labels.device }}] 网卡5分钟平均发送流量超过5Mbps."
value: "{{ $value }}Mbps"
- alert: CPU Usage
配置完成之后重启一下Prometheus服务
等一会验证效果
恢复是下面这个
监控容器就完成了
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享题目:如何在alertmanager报警中添加企业微信监控报警-创新互联
文章网址:http://ybzwz.com/article/dpecso.html