User insight: hardlink breakage only happens at deploy time (scp file replacement / git checkout-merge), so detection must be welded INTO the deploy pipeline, not left to daily audit. Three automatic layers, no reliance on discipline: 1. systemd path watcher (profile-scripts-sync.path): watches deploy/profile-scripts/ directory, auto-fires sync_profile_scripts.sh on any change. Verified: fires within 4s of file replacement, logs to gateway/logs/link_sync.log (runs as hmo user) 2. git hooks (.git/hooks/post-merge + post-checkout on 246 repo): auto re-link after git operations 3. Manual fallback: sync_profile_scripts.sh (now self-logging) dev-spec red line #6 updated: SSOT rule now documents the three layers and states breakage only happens at deploy time.
69 lines
3.1 KiB
Python
69 lines
3.1 KiB
Python
import json, urllib.request
|
||
|
||
msg = """[笑笑] 自检体系 L0-L4 分层架构 — 建成并验证
|
||
|
||
按你的四点要求重构完成:
|
||
|
||
■ 责任矩阵(每层职责单一,不重叠不疏漏)
|
||
|
||
L0 执行心跳 — agents_health_check.py(5min)
|
||
职责:端口/HTTP/DB 存活 + auto_heal 执行(gateway重启/key切换/bot重启)
|
||
|
||
L1 功能健康 — functional_health_check.py(交易时段15min)
|
||
职责:判据是"功能是否达成"不是"进程活着"。9个核心模块各有注册判据:
|
||
· price_monitor → live_prices 最新记录 <6min
|
||
· market_watch → market_snapshots <40min
|
||
· mtf_cache → <75min
|
||
· macro_context → <45min
|
||
· 健康采集 → mofin_health.json <20min
|
||
· 盘前重评 → summary <26h
|
||
· LLM → agent.log 有成功调用
|
||
· bot → systemctl active + 无断线循环
|
||
· cron引擎 → 最近12min有job运行
|
||
|
||
L2 系统卫生 — system_hygiene_audit.py(每日08:20,已从每周改每日)
|
||
职责:分叉副本/断裂硬链接/僵尸进程/孤儿文件/死cron/DB新鲜度
|
||
|
||
L3 LLM修复循环 — self_repair.py(30min)
|
||
职责:读 L1/L2 失败项 → LLM 诊断 → 直接修复(报备制)
|
||
|
||
L4 元监控 — meta_watchdog.py(每小时)
|
||
职责:自检系统的自检——L0-L3 输出物新鲜度 + L3注册状态 + XMPP桥。
|
||
任何一层死亡直接 XMPP 点名(最后兜底)
|
||
|
||
已退休重叠组件:Cron监护-高频(并入L3)、全局cron健康监控(并入L1)
|
||
|
||
■ 报备制(不是报告了事)
|
||
|
||
L3 的纪律:发现问题 → 直接修 → 记录 repair_log.jsonl → XMPP 报备。
|
||
LLM 只许选白名单动作(rerun_script/restart_service/sync_links/switch_llm_key/none),
|
||
不许任意执行代码;每模块每天≤2次防修复循环;白名单兜不住会明说"需要人工"。
|
||
|
||
■ 端到端验证(真实测试)
|
||
|
||
1. 我手动 stop xmpp bot → L1 立即报 fail(bot 服务非 active)
|
||
2. systemd Restart=always 自动拉起 → L3 LLM 诊断后正确判定"无需动作"并记录日志
|
||
3. rerun_script 白名单路径实测:真实重跑 mofin_health.py 成功
|
||
4. meta_watchdog 复检:L0-L4 全绿
|
||
5. 第一版 bot 判据被我自己抓出 bug(信30分钟前日志不看当前状态),已修正为"先看 is-active"
|
||
|
||
■ F健康整合
|
||
|
||
mofin_health.html 新增 🩺自检体系 Tab(在 功能树/全部Cron/数据实体/数据流 之后):
|
||
· L4 元监控各层状态表
|
||
· L1 九项功能判据逐项状态
|
||
· L2 卫生问题清单
|
||
· L3 最近修复动作时间线(报备记录)
|
||
|
||
你打开 Dashboard → 健康 → 🩺自检体系 就能看到系统各方各面的健康状态,
|
||
以及自检系统自身的运转情况。责任矩阵已写入 dev-spec.md 第三章。
|
||
|
||
代码已提交合并(246: e69109fd)。"""
|
||
|
||
payload = json.dumps({"to": "hmo@yoin.fun", "body": msg, "type": "chat"}).encode()
|
||
req = urllib.request.Request("http://127.0.0.1:5805/", data=payload,
|
||
headers={"Content-Type": "application/json"})
|
||
try:
|
||
print("XMPP:", urllib.request.urlopen(req, timeout=10).read().decode()[:80])
|
||
except Exception as e:
|
||
print("XMPP fail:", e) |