二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • 最佳实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • AWS

  • Prometheus

    • Prometheus安装部署及简单监控
    • Prometheus邮件报警配置
      • Prometheus配置Grafana Dashboard
      • Prometheus 监控之 Redis
      • Prometheus 监控之 MySQL
      • 从CPU的获取来学习理解Prometheus查询语句
      • Prometheus监控之kafka集群
      • Prometheus监控之elasticsearch集群
      • Prometheus关于with和by的作用及用法
      • 利用promwrite对prometheus进行remote-write写入
      • prometheus结合nginx-lua-prometheus监控openresty
    • Grafana

    • Loki

    • CentOS

    • Supervisord

    • Systemd

    • Docker

    • Docker-Compose

    • Rancher

    • Ansible

    • OpenLdap

    • GitLab

    • GitHub

    • Etcd

    • Consul

    • RabbitMQ

    • Kafka

    • Mysql

    • MongoDB

    • OpenVPN

    • Kvm

    • VMware

    • 配置文件详解

    • Other

    • 运维观止
    • Prometheus
    二丫讲梵
    2019-02-17
    目录

    Prometheus邮件报警配置

    文章发布较早,内容可能过时,阅读注意甄别。

    # 1、安装配置 Alertmanager

    $ tar xf alertmanager-0.15.2.linux-amd64.tar.gz -C /usr/local/
    $ mv alertmanager-0.15.2.linux-amd64/ alertmanager
    
    1
    2

    # 2,创建启动文件

    $ vim /usr/lib/systemd/system/alertmanager.service
    添加如下内容:
    [Unit]
    Description=alertmanager
    Documentation=https://github.com/prometheus/alertmanager
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alert-test.yml
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    Alertmanager 安装目录下默认有 alertmanager.yml 配置文件,可以创建新的配置文件,在启动时指定即可。

    $ cd /usr/local/alertmanager
    $ vim alert-test.yml
    global:
      smtp_smarthost: 'smtp.163.com:25'
      smtp_from: 'Linuxlql@163.com'
      smtp_auth_username: 'Linuxlql@163.com'
      smtp_auth_password: '123546' # 这里是邮箱的授权密码,不是登录密码
      smtp_require_tls: false
    templates:
      - '/alertmanager/template/*.tmpl'
    route:
      group_by: ['alertname', 'cluster', 'service']
      group_wait: 30s
      group_interval: 5m
      repeat_interval: 10m
      receiver: default-receiver
    receivers:
    - name: 'default-receiver'
      email_configs:
      - to: 'liqilong@edspay.com'
        html: ''
        headers: { Subject: "[WARN] 报警邮件 test" }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    邮箱一开始使用的是公司的邮箱,结果在后边验证的时候,总是会报错level=error ts=2019-01-26T06:21:59.062483579Z caller=notify.go:332 component=dispatcher msg="Error on notify" err="*smtp.plainAuth failed: unencrypted connection",也在这里 (opens new window)看了一些人踩坑的报告,试验了 25、465、587 端口,发现均无效果,最后改成 163 邮箱,直接就生效了。

    • smtp_smarthost:是用于发送邮件的邮箱的 SMTP 服务器地址 + 端口;
    • smtp_auth_password:是发送邮箱的授权码而不是登录密码;
    • smtp_require_tls:不设置的话默认为 true,当为 true 时会有 starttls 错误,为了简单这里设置为 false;
    • templates:指出邮件的模板路径;
    • receivers 下 html 指出邮件内容模板名,这里模板名为 “alert.html”,在模板路径中的某个文件中定义。
    • headers:为邮件标题;

    申明

    原创文章eryajf,未经授权,严禁转载,侵权必究!此乃文中随机水印,敬请读者谅解。

    Copyright 二丫讲梵 (opens new window) 版权所有

    # 3,配置告警规则。

    配置 rule.yml。

    $ cd /usr/local/prometheus
    $ vim rule.yml
    groups:
    - name: alert-rules.yml
      rules:
      - alert: InstanceStatus # alert 名字
        expr: up{job="linux-node01"} == 0 # 判断条件
        for: 10s # 条件保持 10s 才会发出 alter
        labels: # 设置 alert 的标签
          severity: "critical"
        annotations:  # alert 的其他标签,但不用于标识 alert
          description: 服务器  已当机超过 20s
          summary: 服务器  运行状态
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    在 prometheus.yml 中指定 rule.yml 的路径

    $ cat prometheus.yml
    # my global config
    global:
      scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
      evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
      # scrape_timeout is set to the global default (10s).
    # Alertmanager configuration
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          - localhost:9093 # 这里修改为 localhost
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
      - "/usr/local/prometheus/rule.yml"
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
        static_configs:
        - targets: ['localhost:9090','localhost:9100']
      - job_name: '111.4'
        scrape_interval: 5s
        static_configs:
        - targets: ['192.168.111.4:9100']
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30

    重启 Prometheus 服务:

    $ chown -R prometheus.prometheus /usr/local/prometheus/rule.yml
    $ systemctl restart prometheus
    
    1
    2

    # 4,编写邮件模板

    注意:文件后缀为 tmpl

    $ mkdir -pv /alertmanager/template/
    $ vim /alertmanager/template/alert.tmpl
    <table>
        <tr><td>报警名</td><td>开始时间</td></tr>
            <tr><td></td><td></td></tr>
    </table>
    
    1
    2
    3
    4
    5
    6

    # 5,启动 Alertmanager

    $ chown -R prometheus.prometheus /usr/local/alertmanager
    $ systemctl daemon-reload
    $ systemctl start alertmanager.service
    $ systemctl status alertmanager.service
    $ ss -tnl|grep 9093
    
    1
    2
    3
    4
    5

    # 6,验证效果。

    此时到管理界面可以看到如下信息:

    image

    然后停止 111.4 节点上的 node_exporter 服务,然后再看效果。

    $ systemctl stop node_exporter.service
    
    1

    image

    接着邮箱应该会收到邮件:

    image

    微信 支付宝
    #prometheus
    上次更新: 2024/07/04, 22:40:37
    Prometheus安装部署及简单监控
    Prometheus配置Grafana Dashboard

    ← Prometheus安装部署及简单监控 Prometheus配置Grafana Dashboard→

    最近更新
    01
    学习周刊-总第212期-2025年第21周
    05-22
    02
    从赵心童世锦赛夺冠聊聊我的斯诺克情缘
    05-16
    03
    学习周刊-总第211期-2025年第20周
    05-15
    更多文章>
    Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式