git地址 钉钉 参考地址 参考地址2 邮件
❤https://blog.csdn.net/weixin_44953658/article/details/112520122 ❤https://www.cnblogs.com/xuwujing/p/14065740.html
成功案例 邮件
本次实验环境 windows alertmanager-0.21.0.windows-amd64.tar.gz
地址:127.0.0.1:9093
- 下载解压配置 Alertmanager
- Alertmanager.yaml
```yaml
global:
resolve_timeout: 5m
smtp_from: ‘1445763190@qq.com’
smtp_smarthost: ‘smtp.qq.com:465’
smtp_auth_username: ‘1445763190@qq.com’
smtp_auth_password: ‘2342342342342’
smtp_require_tls: false
route:
group_by: [‘instance’]
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: email
routes:
- match: severity: critical receiver: pager
- match_re: severity: ^(warning|critical)$ receiver: support_team
- Alertmanager.yaml
```yaml
global:
resolve_timeout: 5m
smtp_from: ‘1445763190@qq.com’
smtp_smarthost: ‘smtp.qq.com:465’
smtp_auth_username: ‘1445763190@qq.com’
smtp_auth_password: ‘2342342342342’
smtp_require_tls: false
route:
group_by: [‘instance’]
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: email
routes:
receivers:
- name: ‘email’
email_configs:
- to: ‘1445763190@qq.com’
- name: ‘support_team’
email_configs:
- to: ‘1445763190@qq.com’
- name: ‘pager’
email_configs:
- to: ‘1445763190@qq.com’
- 配置 prometheus
- prometheus.yaml
```yaml
# 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:
- '192.168.0.51:9093'
# Alertmanager 的地址
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "first_rules.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: 'appointment'
scrape_interval: 10s
metrics_path: '/appointment/actuator/prometheus'
static_configs:
- targets: ['localhost:9002']
labels:
instance: smartAppointment
- first_rules.yml
groups:
- name: node
rules:
- alert: server_status
expr: up{job="appointment"} == 0
for: 15s
annotations:
summary: "机器{{ $labels.instance }} 挂了"
description: "报告.请立即查看!"
测试中钉钉
alertmanager-0.21.0.linux-amd64.tar.gz CentOS Linux release 7.6.1810 (Core)
- Architecture: x86_64
- Intel(R) Xeon(R)
- 下载解压配置 Alertmanager
- 钉钉Alertmanager.yaml
```yaml
global:
resolve_timeout: 5m
route:
receiver: webhook
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
group_by: [alertname]
routes:
- receiver: webhook group_wait: 10s match: team: node receivers:
- name: webhook
webhook_configs:
- url: https://oapi.dingtalk.com/robot/send?access_token= send_resolved: true
- 配置 prometheus同上邮箱的配置
- [设置自启](https://www.cnblogs.com/Wshile/p/12938377.html)参考
```shell
vi /usr/lib/systemd/system/alertmanager.service
# 添加数据
[Unit]
Description=alertmanager
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
# alertmanager地址
ExecStart=/opt/alertmanager/alertmanager --config.file=/opt/alertmanager/alertmanager.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
chown -R prometheus.prometheus /usr/lib/systemd/system/alertmanager.service
# 启动
systemctl start alertmanager
# 重启
systemctl restart alertmanager
#查看端口
netstat -anpt | grep 9093
- 查看prometheus
-
命令记录
# 下载
wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
# 解压
tar -xvf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
# 重命名
mv prometheus-webhook-dingtalk-1.4.0.linux-amd64 prometheus-webhook-dingtalk
配置文件 ```yaml
Request timeout
timeout: 5s
Customizable templates path
templates:
- /config/example.tmpl
targets: webhook1: &target_base url: https://oapi.dingtalk.com/robot/send?access_token=xxxx message: title: ‘{{ template “example.title” . }}’ text: ‘{{ template “example.content” . }}’
webhook2: <<: *target_base mention:
# 此处必须声明 Mention 的号码...
mobiles: ["我的电话号码"]
message:
text: |
@我的电话号码
{{ template "example.content" . }}
注意
- prometheus.yaml 配置 alertmanagers节点时最好些写ip+prot
- 邮件配置参考报警邮箱配置