完善中央与边缘部署、远程写入与监控文档

- 增加中央与边缘完整配置和部署脚本
- 引入 VictoriaMetrics 数据源与 remote_write 故障排查说明
- 新增 edge-agent 配置脚本、ONVIF 自建 exporter 与 ping 监控示例

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Super User
2026-02-25 04:24:40 -05:00
parent 9e37f79a36
commit 95a09fd9d8
52 changed files with 5978 additions and 0 deletions

300
doc/ALERTMANAGER_CONFIG.md Normal file
View File

@@ -0,0 +1,300 @@
# Alertmanager 配置说明
## 配置文件概述
`alertmanager.yml` 是 Alertmanager 的核心配置文件,用于定义告警路由、通知方式和告警抑制规则。
## 配置详解
### 1. Global全局配置
```yaml
global:
smtp_smarthost: 'localhost:587'
smtp_from: 'alertmanager@example.com'
```
**作用**:定义全局的 SMTP 邮件服务器配置
**字段说明**
- `smtp_smarthost`: SMTP 服务器地址和端口
- 当前配置:`localhost:587`(本地邮件服务器)
- 如果使用外部邮件服务,例如:
- Gmail: `smtp.gmail.com:587`
- 163邮箱: `smtp.163.com:465`
- 企业邮箱: `smtp.company.com:587`
- `smtp_from`: 发送告警邮件的发件人地址
- 当前配置:`alertmanager@example.com`(示例地址,需要修改)
**注意**:当前配置使用的是 webhook所以 SMTP 配置暂时未使用。
---
### 2. Route路由配置
```yaml
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'web.hook'
```
**作用**:定义告警的路由规则,决定告警如何分组和发送
**字段说明**
| 字段 | 说明 | 当前值 | 含义 |
|------|------|--------|------|
| `group_by` | 告警分组字段 | `['alertname']` | 按告警名称分组,相同名称的告警会被合并 |
| `group_wait` | 分组等待时间 | `10s` | 收到第一个告警后等待10秒再发送用于合并同类告警 |
| `group_interval` | 分组间隔 | `10s` | 同一分组内新告警的发送间隔 |
| `repeat_interval` | 重复间隔 | `1h` | 如果告警持续存在每1小时重复发送一次通知 |
| `receiver` | 默认接收器 | `'web.hook'` | 所有告警默认发送到 `web.hook` 接收器 |
**示例场景**
- 如果 3 个设备同时离线,会在 10 秒内合并为一条告警发送
- 如果告警持续存在,每小时会重复通知一次
---
### 3. Receivers接收器配置
```yaml
receivers:
- name: 'web.hook'
webhook_configs:
- url: 'http://127.0.0.1:5001/'
```
**作用**:定义告警通知的接收方式
**当前配置**
- **接收器名称**`web.hook`
- **通知方式**WebhookHTTP POST
- **目标地址**`http://127.0.0.1:5001/`
**说明**
- 告警会以 JSON 格式 POST 到指定的 URL
- 需要有一个服务监听 `127.0.0.1:5001` 来处理告警
- 如果没有这个服务,告警通知会失败
**其他可用的接收器类型**
- `email_configs` - 邮件通知
- `wechat_configs` - 企业微信通知
- `dingtalk_configs` - 钉钉通知
- `slack_configs` - Slack 通知
- `webhook_configs` - 自定义 Webhook
---
### 4. Inhibit Rules抑制规则
```yaml
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
```
**作用**:定义告警抑制规则,避免重复告警
**当前规则说明**
- **源匹配**:如果存在 `severity: critical` 的告警
- **目标匹配**:则抑制 `severity: warning` 的告警
- **匹配条件**:当 `alertname``dev``instance` 标签相同时
**示例场景**
- 如果设备离线critical则不再发送该设备的温度过高warning告警
- 避免告警风暴,只关注最严重的问题
**注意**:当前配置中的 `dev` 标签可能不存在,建议修改为实际使用的标签。
---
## 配置流程图
```
Prometheus 触发告警
Alertmanager 接收告警
├─> 按 alertname 分组
├─> 等待 10sgroup_wait
├─> 应用抑制规则
发送到接收器 (web.hook)
POST 到 http://127.0.0.1:5001/
```
---
## 常见配置场景
### 场景 1邮件通知
```yaml
receivers:
- name: 'email'
email_configs:
- to: 'admin@example.com'
from: 'alertmanager@example.com'
smarthost: 'smtp.gmail.com:587'
auth_username: 'your-email@gmail.com'
auth_password: 'your-password'
```
### 场景 2企业微信通知
```yaml
receivers:
- name: 'wechat'
wechat_configs:
- api_url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send'
corp_id: 'your-corp-id'
to_user: '@all'
```
### 场景 3多接收器根据严重程度
```yaml
route:
routes:
- match:
severity: critical
receiver: 'critical-alerts'
- match:
severity: warning
receiver: 'warning-alerts'
receiver: 'default'
receivers:
- name: 'critical-alerts'
email_configs:
- to: 'oncall@example.com'
- name: 'warning-alerts'
webhook_configs:
- url: 'http://127.0.0.1:5001/'
```
---
## 当前配置的问题和建议
### 问题 1Webhook 服务不存在
**当前配置**`http://127.0.0.1:5001/`
**问题**:如果没有服务监听这个端口,告警通知会失败
**解决方案**
1. **部署 Webhook 接收服务**(推荐用于开发测试)
2. **配置邮件通知**(推荐用于生产环境)
3. **配置企业微信/钉钉**(推荐用于团队协作)
### 问题 2抑制规则标签不匹配
**当前配置**`equal: ['alertname', 'dev', 'instance']`
**问题**`dev` 标签可能不存在于告警中
**建议修改**
```yaml
equal: ['alertname', 'instance']
```
### 问题 3SMTP 配置未使用
**当前配置**SMTP 配置存在但未使用
**建议**
- 如果使用邮件通知,需要配置正确的 SMTP 服务器
- 如果只使用 Webhook可以删除 SMTP 配置
---
## 验证配置
### 1. 检查配置语法
```bash
docker exec alertmanager amtool check-config /etc/alertmanager/alertmanager.yml
```
### 2. 查看告警状态
访问 Alertmanager Web UI
```
http://localhost:9093
```
### 3. 测试告警
在 Prometheus 中手动触发告警,查看是否收到通知。
---
## 配置示例(推荐)
### 最小化 Webhook 配置
```yaml
route:
group_by: ['alertname', 'instance']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'web.hook'
receivers:
- name: 'web.hook'
webhook_configs:
- url: 'http://127.0.0.1:5001/'
send_resolved: true # 发送恢复通知
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'instance']
```
### 邮件通知配置
```yaml
global:
smtp_smarthost: 'smtp.gmail.com:587'
smtp_from: 'alertmanager@example.com'
smtp_auth_username: 'your-email@gmail.com'
smtp_auth_password: 'your-app-password'
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'email'
receivers:
- name: 'email'
email_configs:
- to: 'admin@example.com'
send_resolved: true
```
---
## 下一步
1. **配置通知渠道**:根据实际需求配置邮件、企业微信、钉钉等
2. **测试告警**:确保告警能够正常发送
3. **优化路由规则**:根据业务需求调整告警分组和路由
4. **设置告警抑制**:避免告警风暴