AlertManagerアラーム配信ルーティング構成(10)

AlertManagerアラーム配信ルーティング構成

1.ルート設定ファイルの紹介

route:
  group_by: ['alertname']								//定义分组
  group_wait: 10s								//分组等待时间
  group_interval: 10s						//收到告警后多长时间发送给接收者
  repeat_interval: 10m							//重复告警间隔
  receiver: 'yunwei'							//默认邮箱
  routes:									//启用一个子路由
  - receiver: 'dba'								//接收者为dba
    group_wait: 10s									//分组等待时间
    match_re:								//匹配一个正则
      service: mysql|db						//service标签包含mysql和db的统一发送给dba的邮箱
  - receiver: 'yunwei'					//接收者为yunwei
    group_wait: 10s							//分组时间
    match_re:		
      service: error								//将service标签值包含error的发送给yunwei的邮箱
	
receivers:							//定义接收者的邮箱
- name: 'yunwei'							//接收者名字,要和routes中的receiver对应
  email_configs:				
  - to: '[email protected]'						//yunwei的邮箱地址
- name: 'dba'								//接收者名字,要和routes中的receiver对应
  email_configs:		
  - to: '[email protected]'						//dba的邮箱地址

2.要件の説明

要件:サーバータグには、dbおよびmysql用にdbaに送信されるメールボックスが含まれ、その他はすべて、運用および保守のメールボックスに送信されます。

最終的な効果:mysqlおよびその他のデータベースに関するアラームをdbaに送信し、その他の情報を運用および保守に送信するように要求します。

ここに画像の説明を挿入

3.Alertmanagerは、異なるアラームコンテンツが異なる受信者に送信されることを認識します

3.1。構成ファイルを変更します

1.修改配置文件
[root@prometheus-server /data/AlertManager]# vim AlertManager.yml  
global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.qq.com:465'
  smtp_from: '[email protected]'
  smtp_auth_username: '[email protected]'
  smtp_auth_password: 'yzjqxhsranbpdijd'
  smtp_require_tls: false

route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 10m
  receiver: 'yunwei'
  routes:
  - receiver: 'dba'
    group_wait: 10s
    match_re:
      service: mysql|db
  - receiver: 'yunwei'
    group_wait: 10s
    match_re:
      serverity: error

receivers:
- name: 'yunwei'
  email_configs:
  - to: '[email protected]'
- name: 'dba'
  email_configs:
  - to: '[email protected]'

2.重启生效
[root@prometheus-server /data/AlertManager]# ps aux | grep alert | grep -v grep | awk '{print $2}' |xargs kill -HUP

ここに画像の説明を挿入

構成が有効になりました

ここに画像の説明を挿入

3.2.mysqlアラームルールを定義する

3.2.1.node_exporterを開いてmysqlを監視します

起動時に直接mysqlサービス監視を追加します

[root@192_168_81_220 ~]# vim /usr/lib/systemd/system/node_exporter.service
ExecStart=/data/node_exporter/node_exporter --collector.systemd --collector.systemd.unit-whitelist=(docker|sshd|node_exporter|mariadb).service

[root@192_168_81_220 ~]# systemctl daemon-reload 
[root@192_168_81_220 ~]# systemctl restart node_exporter.service 

ページにすでにmysqlモニタリングがあるかどうかを確認します

node_systemd_unit_state{name="mariadb.service",state="active"}

ここに画像の説明を挿入

3.2.2。アラームルールを書く

1.编写规则
[root@prometheus-server /data/prometheus]# vim rules/hostdown.yml 
groups:
- name: general.rules
  rules:
  - alert: 主机宕机
    expr: up == 0
    for: 1m
    labels:
      serverity: error
    annotations:
      summary: "主机 {
   
   { $labels.instance }} 停止工作"
      description: "{
   
   { $labels.instance }} job {
   
   { $labels.job }} 已经宕机5分钟以上!"

  - alert: mysql服务器异常
    expr: up{job="mysql"} == 0
    labels:
      service: mysql
    annotations:
      summary: "主机 {
   
   { $labels.instance }} mysql 停止工作"
      description: "{
   
   { $labels.instance }} mysql服务已经异常5分钟以上!"

2.加载配置
[root@prometheus-server /data/prometheus]# curl -XPOST 192.168.81.210:9090/-/reload

3.3.mysqlアラームをトリガーします

3.3.1.192.168.81.220でmysql_exporterを停止します

[root@192_168_81_220 ~]# ps aux | grep mysql_exporter | awk '{print $2}' |xargs kill -9 

3.3.2.alertアラームが送信されました

ここに画像の説明を挿入

3.3.3。エラーが運用および保守メールボックスに送信されました

ここに画像の説明を挿入

3.3.4.mysqlがdbaメールボックスに送信されました

ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_44953658/article/details/113777167
おすすめ