Files
telegram-customer-bot/SMART_MONITORING.md
2025-11-01 21:58:31 +08:00

132 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 智能监控系统配置
更新时间: 2025-10-30 06:01
## 设计原则
**只在有问题时干预 - 正常运行时不碰它**
## 定时任务配置
### 1. Session 自动备份
```
时间: 每 6 小时0, 6, 12, 18点
命令: ./protect_session.sh
功能:
- 备份 session 文件
- 自动恢复(如果丢失)
- 保留 7 天历史
```
### 2. 智能健康检查
```
时间: 每 12 小时0点和12点
命令: ./smart_health_check.sh
功能:
- 检查机器人进程
- 检查 Pyrogram 连接
- 检查最近错误
- 只在有问题时重启
```
## 智能检查逻辑
### 检查项目
1. ✅ 机器人进程是否运行
2. ✅ Pyrogram 客户端状态
3. ✅ 最近1小时 Connection lost 错误
4. ✅ 最近1小时 AUTH_KEY 错误
### 触发重启条件(满足任一条件)
- ❌ 机器人进程未运行
- ❌ Connection lost 错误 > 5个1小时内
- ❌ AUTH_KEY 错误 > 0个1小时内
- ❌ Pyrogram 状态异常 + Connection 错误 > 2个
### 正常运行时
- ✅ 检查所有状态
- ✅ 记录日志
-**不采取任何行动**
## 对比之前的配置
### 之前(过于激进)
- 每 15 分钟检测并可能重启
- 每 30 分钟监控
- 频繁干预
### 现在(温和智能)
- 每 12 小时检查一次
- 只在真正有问题时干预
- 让系统自然运行
## 运行记录
### 首次测试 (2025-10-30 05:59:46)
```
✅ Pyrogram 客户端状态: 正常
✅ 最近1小时 Connection lost 错误: 0 个
✅ 最近1小时 AUTH_KEY 错误: 0 个
✅ 一切正常,无需干预
操作: 无操作
```
## 日志文件
- `logs/smart_health_check.log` - 检查记录
- `logs/session_backup.log` - 备份记录
- `logs/integrated_bot_errors.log` - 机器人错误
## 查看命令
**查看定时任务**
```bash
crontab -l
```
**查看检查日志**
```bash
tail -50 ~/telegram-bot/logs/smart_health_check.log
```
**手动运行检查**
```bash
cd ~/telegram-bot && ./smart_health_check.sh
```
**查看机器人状态**
```bash
ps aux | grep integrated_bot
```
## 时间表
```
00:00 - 智能健康检查 + Session备份
06:00 - Session备份
08:00 - 每日自检(系统原有)
12:00 - 智能健康检查 + Session备份
18:00 - Session备份
```
## 预期效果
1. ✅ 系统正常运行时:完全不干预
2. ✅ 出现小问题时:等待自然恢复
3. ✅ 出现严重问题时:自动重启恢复
4. ✅ Session 定期备份:防止数据丢失
## 维护建议
- 定期查看日志(每周一次)
- 如果频繁重启,检查根本原因
- 备份文件每月清理一次(自动)
---
**总结**:
- 每12小时检查一次
- 只在真正有问题时采取行动
- 让系统保持自然稳定运行