Prometheus + AlertManager 邮件报警

安装

wget https://github.com/prometheus/alertmanager/releases/download/v0.13.0/alertmanager-0.13.0.linux-amd64.tar.gz
tar -axvf alertmanager-0.13.0.linux-amd64.tar.gz

配置AlertManager

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

配置文件如下:

global:
  smtp_smarthost: ‘smtp.163.com:25‘
  smtp_from: ‘[email protected]‘
  smtp_auth_username: ‘[email protected]‘
  smtp_auth_password: ‘admin123‘
  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: ‘[email protected]‘
    html: ‘{{ template "alert.html" . }}‘
    headers: { Subject: "[WARN] 报警邮件test" }
smtp_smarthost是用于发送邮件的邮箱的SMTP服务器地址+端口
smtp_auth_password是发送邮箱的授权码而不是登录密码
smtp_require_tls不设置的话默认为true,当为true时会有starttls错误,可以用其他办法解决。为了简单这里直接设置为false
templates指出邮件的模板路径
receivers下html指出邮件内容模板名,这里模板名为“alert.html”,在模板路径中的某个文件中定义
headers为邮件标题

配置Prometheus报警规则

配置rule.yml

groups:
- name: test-rule
  rules:
  - alert: clients
    expr: redis_connected_clients > 1
    for: 1m
    labels:
      severity: warning
    annotations:
      summary: "{{$labels.instance}}: Too many clients detected"
      description: "{{$labels.instance}}: Client num is above 80% (current value is: {{ $value }}"

在prometheus.yml中指定rule.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"]

# Load rules once and periodically evaluate them according to the global ‘evaluation_interval‘.
rule_files:
   - /rule.yml
  # - "second_rules.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‘]

  - job_name: redis_exporter

    static_configs:
      - targets: [‘localhost:9122‘]

编写邮件模板

文件后缀为tmpl

{{ define "alert.html" }}
<table>
    <tr><td>报警名</td><td>开始时间</td></tr>
    {{ range $i, $alert := .Alerts }}
        <tr><td>{{ index $alert.Labels "alertname" }}</td><td>{{ $alert.StartsAt }}</td></tr>
    {{ end }}
</table>
{{ end }}

启动各个组件

启动AlertManager

cd /home/admin/alertmanager-0.13.0.linux-amd64
./alertmanager --config.file=alert.yml

启动Prometheus

cd /home/admin/prometheus-2.1.0.linux-amd64
./prometheus --config.file=prometheus.yml

启动exporter

cd  /prometheus_exporters
./node_exporter & 
./redis_exporter redis//localhost:6379 & -web.listenaddress 0.0.0.0:9122

效果

收到的邮件

 

原文地址:https://www.cnblogs.com/jugglee/p/8432262.html

时间: 2024-08-30 05:12:22

Prometheus + AlertManager 邮件报警的相关文章

prometheus altermanager邮件报警

prometheus altermanager邮件报警: 下载网址:https://prometheus.io/download tar zxfv alertmanager-0.15.2.linux-amd64.tar.gz -C /space/ mv /space/alertmanager-0.15.2.linux-amd64 /Influxdb/alertmanager vi /space/altermanager/altermanager.yml global:resolve_timeou

【转帖】Prometheus AlertManager 微信报警配置

Prometheus AlertManager 微信报警配置 https://segmentfault.com/a/1190000015400227 改天尝试一下 prometheus 阅读约 5 分钟 Prometheus AlertManager 微信报警配置 alertmanager支持email,webhook等报警源支持,看到可以支持微信报警信息推送觉得有意思把玩一下,alertmanager的0.15版本微信报警推送有问题,后来我把版本降到0.14后微信就能正常收到报警信息 微信企业

部署kube-prometheus,添加邮件报警

这个项目出自coreos,已经存在很久了,第一次尝试的时候还很简陋,现在完善了很多. 项目提供了一键部署脚本,跑起来并不难,不过个人感觉要真正掌握并灵活使用并不是很容易. kube version: 1.9.1 OS version: debian stretch 1.从github把项目拉下来. # git clone https://github.com/coreos/prometheus-operator.git 2.准备镜像,这里用到了墙外的镜像,自行科学下载. quay.io/prom

线上一个简单检测Ping状态的邮件报警脚本

Step1.安装sendmail来发邮件 # yum -y install sendmail # /etc/init.d/sendmail start # chkconfig sendmail on Step2.安装邮件客户端 # yum -y install mutt 2.1添加发件人信息,如下 # vim /etc/Muttrc set charset="utf-8"           #设置发邮件编码 set envelope_from=yes set rfc2047_para

图文详解zabbix的安装以及设置邮件报警

简介:1.zabbix的介绍 2.zabbix的服务端安装 3.浏览器安装zabbix 4.zabbix的客户端安装 5.添加一个客户端 6.设置邮件报警 zabbix的介绍 zabbix(音同 zbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题. zabbix由2部分构成,zabbix server与可选组件zabbix agent.

zabbix3.0微信邮件报警

Zabbix 邮件微信报警 分2大部分: 1.Zabbix服务器端配置 邮件服务安装配置 2.Web端服务配置 服务器端的设置: 系统 cenots 6.5   2.6.32-431.el6.x86_64 安装邮件发送服务: [[email protected] ~]# wget http://sourceforge.net/projects/heirloom/files/latest/download?source=files [[email protected] ~]# mv downloa

zabbix源码安装,自定义监控205的用户数,有触发器但没有邮件报警

zabbix源码安装,自定义监控205的用户数,有触发器但没有邮件报警 监控端配置:(192.168.4.5) 1基础环境:(实验环境可以关闭防火墙,但生产环境不能关闭,否则不安全,要设置相应规则) [[email protected]桌面]# /etc/init.d/iptables stop [[email protected]桌面]# setenforce 0 2搭建lamp平台,(它运行在lamp平台上) [[email protected]桌面]# yum -y install htt

zabbix配置邮件报警(第四篇)

邮件报警可采用本地邮件服务,也可以自定义脚本,这里我采用本地邮件服务报警 添加收件人

linux 下搭建zabbix邮件报警

一.搭建环境介绍 hostname IP zabbix版本 系统版本 服务端 webserver 192.168.1.20 zabbix2.2 CentOS 6.6 客户端 hpf-linux 192.168.1.110 zabbix2.2 CentOS 6.6 二.使用外部邮箱账号发送报警邮件设置: 1.关闭sendmail或者postfix 使用外部邮箱账号时,不需要启动sendmail或者postfix ,如果在sendmail或者postfix启动的同时使用外部邮箱发送报警邮件,首先会读