• Prometheus 之安装 Alertmanager告警模块:


    Alertmanager 介绍
    alertmanager是Prometheus中的一个独立的告警模块,接受Prometheus发来警报,然后通过分组、删除重复等处理,并将他们通过路由发送给正确的接收器。

    Prometheus 的警报由称为Alertmanager的工具提供,这是监控环境的独立部分。警报规则在Prometheus服务器上定义。这些规则可以触发事件,然后将其传播到Alertmanager 模块,Alertmanager随后决定如何处理各自的警报,处理复制之类的问题,并决定在发送警报时使用什么机制:实时消息、电子邮件或其它工具。

    部署服务:

    官网下载地址:
    https://prometheus.io/download/

    https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz

    1、下载后进行解压缩

    
    
    # tar -zxvf alertmanager-0.21.0.linux-amd64.tar.gz -C /usr/local/
    # mv alertmanager-0.21.0.linux-amd64/ alertmanager

    2、修改alertmanager配置文件:

    ]# vim alertmanager.yml
    
    global:
      # resolve_timeout:解析超时时间
      resolve_timeout: 5m
      # smtp_smarthost: 使用email打开服务配置
      smtp_smarthost: 'mail.com:25'
      smtp_from: '57@.com'
      smtp_auth_username: '57@.com'
      smtp_auth_password: 'i@293909'
      smtp_require_tls: false
    
    # route标记:告警如何发送分配
    route:
      group_by: ['alertname']
      group_wait: 10s
      group_interval: 10s
      repeat_interval: 1h
    
      # receiver 定义谁来通知报警
      receiver: 'mail'
    
    # receiver标记:告警接受者
    receivers:
    - name: 'mail'
      email_configs:
      # to:指定接收端email
      - to: 'yl2021@163.com,57@.com'
    
    # inhibit_rules标记:降低告警收敛,减少报警,发送关键报警
    #inhibit_rules:
    #  - source_match:
    #      severity: 'critical'
    #    target_match:
    #      severity: 'warning'
    #    equal: ['alertname', 'dev', 'instance']
    #

    3、检查alertmanager配置文件

    [root@localhost alertmanager]# ./amtool check-config alertmanager.yml
    Checking 'alertmanager.yml'  SUCCESS
    Found:
     - global config
     - route
     - 0 inhibit rules
     - 1 receivers
     - 0 templates
    
    [root@localhost alertmanager]# 

    4、启动alertmanager

    [root@localhost alertmanager]#./alertmanager --config.file=alertmanager.yml

    5、将alertmanager添加系统服务:

    # cat  /usr/lib/systemd/system/alertmanager.service
    [Unit]
    Description=alertmanager
    Documentation=https://prometheus.io/
    After=network.target
      
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/usr/local/alertmanager/alertmanager  --config.file=/usr/local/alertmanager/alertmanager.yml
    Restart=on-failure
      
    [Install]
    WantedBy=multi-user.target
    [root@localhost system]# 

    6、启动添加后的系统服务:

    # systemctl daemon-reload
    # systemctl restart alertmanager.service

    至此,alertmanager的配置基本完成,下来就是在prometheus上面配置添加alertmanager的支持.

    7、编辑Prometheus配置文件配置连接地址:

    # 编辑Prometheus配置文件配置连接地址:vim prometheus.yml
    [root@localhost prometheus]# vim prometheus.yml
    # Alertmanager configuration
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
           - 10.0.2.118:9093
    
    # 编辑Prometheus配置文件配置,开启告警配置文件:
    [root@localhost prometheus]# vim prometheus.yml
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
    
      # 告警规则配置文件位置
      - "rules/*.yml"

    8、创建告警规则目录,并重启服务.

    [root@localhost prometheus]# mkdir rules
    [root@localhost prometheus]# systemctl restart prometheus

    9、http://10.0.2.118:9093/#/status 验证是否正常.

     10、创建告警规则配置文件并写入规则:vim rules/test.yml

    # cat /usr/local/prometheus/rules/test.yml 
    # groups:组告警
    groups:
    # name:组名。报警规则组名称
    - name: general.rules
      # rules:定义角色
      rules:
      # alert:告警名称。 任何实例5分钟内无法访问发出告警
      - alert: InstanceDown
        # expr:表达式。 up = 0 相当于指标挂掉了
        expr: up == 0
        # for:持续时间。 表示持续一分钟获取不到信息,则触发报警。0表示不使>
        for: 1m
        # labels:定义当前告警规则级别
        labels:
          # severity: 指定告警级别。
          severity: error
        # annotations: 注释 告警通知
        annotations:
          # 调用标签具体指附加通知信息
          summary: "Instance {{ $labels.instance  }} 停止工作" # 自定义摘要
          description: "{{ $labels.instance  }} job {{ $labels.job  }}"

    11、检查配置重启服务

    # ./promtool check config prometheus.yml
    # systemctl restart prometheus.service

    12、监控端查看规则。

     

  • 相关阅读:
    《人月神话》读后感
    十天冲刺计划(第二次)
    日历表的事件处理和管理(刘静)
    十天冲刺计划
    结组开发项目(TD学生助手)
    电梯调度(二)
    敏捷软件开发方法综述
    对于二维数组求子数组的和的最大值
    电梯调度(一)
    FloatyFish休闲游戏 Beta正式发布
  • 原文地址:https://www.cnblogs.com/saneri/p/14755292.html
Copyright © 2020-2023  润新知