GPE监控预警系统-alertmanager配置介绍.md

Alertmanager

在prometheus 中告警分为两部分:

  • prometheus 服务根据所设置的告警规则将告警信息发送给 Alertmanager
  • Alertmanager 对收到的告警信息进行处理,包括:忽略,禁止,聚合或者通过邮件等方式发送告警消息

使用告警服务主要的步骤如下:

  • 下载配置 Alertmanager
  • 通过设置 -alertmanager.url 让prometheus服务与Alertmanager进行通信
  • 在prometheus服务中设置告警规则

安装

cd /op/monitor
wget https://github.com/prometheus/alertmanager/releases/download/\
v0.12.0/alertmanager-0.12.0.linux-amd64.tar.gz

tar xf alertmanager-0.12.0.linux-amd64.tar.gz
cd alertmanager-0.12.0.linux-amd64
# 启动alertmanager
nohup ./alertmanager --config.file=simple.yml >> /var/log/alertmanage.log 2>&1 &
# 重启 prometheus 
nohup prometheus --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml  \
--storage.tsdb.path=/opt/monitor-data >> /var/log/monitor.log 2>&1 &

告警配置

####通过 Email 接收告警

本章将通过一个简单的实验介绍如何通过Email接受告警。

相关信息说明:

  • prometheus版本: prometheus-2.0.darwin-amd64
  • alertmanager版本: alertmanager-0.12.0.darwin-amd64
  • 发送告警邮件的邮箱: qq email
  • 假设该实验运行在本地机器上。prometheus默认端口为9090,Alertmanager默认端口为 9093.

step 1: 配置AlertManager下的simple.yml

其中一些关键配置如下:

    global:
        smtp_smarthost: 'smtp.qq.com:587'
        smtp_from: 'xxx@qq.com'
        smtp_auth_username: 'xxx@qq.com'
        smtp_auth_password: 'your_email_password'

    route:
        # If an alert has successfully been sent, wait 'repeat_interval' to resend them.
        repeat_interval: 10s    
        #  A default receiver
        receiver: team-X-mails  


    receivers:
        - name: 'team-X-mails'
            email_configs:
            - to: 'team-X+alerts@example.org'

step 2: 在prometheus下添加 alert.rules 文件

文件中写入以下简单规则作为示例。

groups:
- name: all.yml
  rules:    
  - alert: Network_traffic_to Hight
    expr: rate(node_network_receive_bytes[30s])/1000 > 500000
    for: 2m
    labels:
      service: system
      severity: warning
    annotations:
      description: '工作组{{ $labels.job }} 中{{ $labels.instance }}({{ $labels.ip }})服务器流量持续两分钟超过50Mb/s,当前值{{ $value }}Kb/s'
      summary: Instance {{ $labels.instance }} traffic warning

step 3: 修改prometheus.yml 文件

添加以下规则:

    rule_files:
       - "alert.rules"

step 4: 启动AlertManager服务

    ./alertmanager -config.file=simple.yml

step 5: 启动prometheus服务

    ./prometheus -alertmanager.url=http://localhost:9093

根据以上步骤设置,此时 “team-X+alerts@example.org” 应该就可以收到 “xxx@qq.com” 发送的告警邮件了。

转载于:https://my.oschina.net/neverforget/blog/1613271

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值