--- name: morning-health-check title: MoFin 系统常规体检机制 description: 每日开盘前8:00全面扫荡式系统体检,含分层分类检查清单、自动发现新增组件、问题推送 trigger: 交易日 8:00 AM 自动运行 --- # MoFin 系统常规体检机制 ## 设计目的 "人的常规体检,不是因为发现问题去针对性检查,而是定期的、全面的、扫荡式的检查。" 核心机制: 1. **health_checklist.json** — 可动态维护的检查清单(新增功能自动加入) 2. **morning_health_check.py** — 每日8:00开盘前运行,逐项比对 3. **self_discovery()** — 自动发现新增cron任务并追加到检查清单 4. **历史追踪** — health_check_history.json 保留90天体检记录 ## 架构 ```python morning_health_check.py (no_agent, 8:00 Cron) │ ├── 读 health_checklist.json (检查清单) │ ├── 分层检查 (7层) │ ├── 基础设施 — XMPP/Gateway/Dashboard/API/磁盘 │ ├── SENSE — price_monitor/xiaoguo/宏观/汇率/板块 │ ├── RESPOND — 推送cron/价格事件/信号积压 │ ├── ADAPT — 策略重评/策略树/时效性 │ ├── IMPROVE — 知识萃取/硬编码/审计/剪枝/元成长 │ ├── 数据文件 — 全部关键JSON/DB文件新鲜度 │ └── 管道完整性 — cron异常/误暂停/delivery目标/信号桥 │ ├── self_discovery() — 自动发现新组件 │ └── 对比jobs.json vs checklist中的cron ID │ └── 发现新cron → 自动追加到pipeline类 │ └── 输出 (no_agent规则) ├── 有异常 → 打印详细报告 (推送给老爸) └── 正常 → [SILENT] ``` ## 检查清单 (health_checklist.json) 位于 `/home/hmo/MoFin/data/health_checklist.json` 7个分类,当前约43项检查。每个检查项包含: - id/description: 唯一标识和描述 - check: 检查指令 (如 `cron:job_id`, `systemctl:service`, `port:8643`, `db:table:field::today:1`) - expected: 期望值 - severity: critical/high/medium/low ## 自维护机制 ### 自动发现 (self_discovery) 每次运行体检时,脚本自动: 1. 读取 Hermes cron 的 jobs.json 2. 对比 checklist 中已登记的 cron ID 3. 发现新 cron 任务 → 自动追加到 pipeline 分类(标记 auto_discovered=true) ### 手动维护 - 新功能加入系统后,应在 checklist 中追加相应检查项 - 修改现有组件后,审视是否需要调整已有检查项的阈值/预期值 ## 检查器类型 | 类型 | 格式 | 说明 | |------|------|------| | systemctl | `systemctl:service_name` | 检查systemd服务 | | port | `port:8888` | 端口监听检查 | | proc | `proc:pattern` | pgrep进程匹配 | | http | `http:url` | HTTP GET可达性 | | disk | `disk:/` | 磁盘使用率 | | fileexists | `fileexists:/path` | 文件是否存在 | | filefresh | `filefresh:/path:24h` | 文件新鲜度 | | db | `db:table:field::today:1` | 数据库记录数 | | cron | `cron:job_id` | Cron任务状态 | | cron_errors | `cron_errors:last24h` | 全局cron异常 | | cron_paused | `cron_paused:check` | 误暂停检查 | | delivery | `delivery:origin_targets` | 推送目标检查 | | pipeline | `pipeline:xiaoguo_signal_flow` | 综合管道检查 | ## 触发方式 - **自动**: cron `0 8 * * 1-5` (交易日8:00, no_agent模式) - **手动**: `python3 /home/hmo/MoFin/scripts/morning_health_check.py --report` - **更新清单**: `python3 /home/hmo/MoFin/scripts/morning_health_check.py --update-checklist` ## 输出格式 ``` MoFin 系统体检 | 2026-06-25 周四 | 08:00 ──────────────────────────────────────── 【基础设施层】 ✅ 知微 XMPP Bot: active ❌ 小果 LLM API: timeout ... (只输出有问题的分类;正常分类仅在 --report 时显示) 【管道完整性】 🔴 无异常cron状态(最近24h): 1 errors: 小果独立扫描(error) ──────────────────────────────────────── 总计: 🔴1严重 | ❌2错误 | ⚠️0警告 | ✅40正常 (15s) 需立即处理的问题: [ERROR] SENSE: 小果扫描 cron 已调度: status=error ``` ## 历史记录 保存在 `/home/hmo/MoFin/data/health_check_history.json` - 每次运行记录时间戳、各等级计数、耗时 - 保留最近90条(约3个月)