#!/bin/bash # 织忆每日健康检查脚本 # 用法: ./daily-check.sh # 依赖: curl, jq (optional) API_KEY="zhiyi-dev-key-2026" BASE="http://localhost:7821" RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m' pass() { echo -e "${GREEN}✅ $1${NC}"; } warn() { echo -e "${YELLOW}⚠️ $1${NC}"; } fail() { echo -e "${RED}❌ $1${NC}"; } echo "=== 织忆每日健康检查 $(date '+%Y-%m-%d %H:%M') ===" # 1. 服务存活 STATUS=$(curl -s $BASE/health | python3 -c "import sys,json; print(json.load(sys.stdin).get('status','?'))" 2>/dev/null) [ "$STATUS" = "ok" ] && pass "服务存活" || fail "服务状态: $STATUS" # 2. 核心统计 STATS=$(curl -s $BASE/api/v1/stats -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$STATS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"记忆: {d.get('total_memories',0)}, Episodes: {d.get('total_episodes',0)}, 坟场: {d.get('tombstone_count',0)}\")" 2>/dev/null # 3. 自优化指标 METRICS=$(curl -s $BASE/api/v1/metrics/self -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$METRICS" | python3 -c " import sys,json d=json.load(sys.stdin) # 2026-10-17:recall_hit_rate 已退役(恒=1、无区分度)。召回质量改用 recall_usefulness_rate #(返回且被使用);-1 表示样本不足/无负反馈 = 数据不可解读,跳过告警,不误报。 hit = d.get('recall_usefulness_rate', -1) loss = d.get('avg_distill_loss', -1) gap = d.get('gap_closure_rate', -1) auto = d.get('auto_resolve_rate', -1) # -1 哨兵 = 样本不足/越界被拦,不可解读 ⇒ 显示 —(N/A),不得当成具体数字误导。 def fmt(v, pct=False): if v is None or v < 0: return '—(N/A)' return ('%.0f%%' % (v*100)) if pct else ('%.2f' % v) print('召回有用率: %s, 蒸馏损失: %s, gap闭合率: %s, auto_resolve率: %s' % (fmt(hit, True), fmt(loss), fmt(gap, True), fmt(auto, True))) if loss is not None and loss >= 0 and loss > 0.3: print('⚠️ avg_distill_loss 超标') if hit is not None and hit >= 0 and hit < 0.5: print('⚠️ recall_usefulness_rate 低于阈值') " 2>/dev/null # 4. 蒸馏状态 DISTILL=$(curl -s $BASE/api/v1/distill/status -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$DISTILL" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"蒸馏队列: {d.get('queue_len',0)}, 今日已蒸: {d.get('daily_used',0)}, 剩余: {d.get('daily_remaining',0)}\")" 2>/dev/null # 5. 触发器 TRIGGERS=$(curl -s $BASE/api/v1/triggers -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$TRIGGERS" | python3 -c " import sys,json d=json.load(sys.stdin) for t in d.get('triggers',[]): fail = t.get('fail_count',0) urgency = t.get('urgency',0) paused = t.get('paused',False) status = '⏸' if paused else ('❌' if fail>0 else '✅') print(f\"{status} {t['id']}: cooldown={t.get('cooldown','')}, fail={fail}, urgency={urgency}\") " 2>/dev/null # 6. 图谱 GRAPH=$(curl -s $BASE/api/v1/graph/stats -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$GRAPH" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"图谱: {d.get('node_count',0)} 节点, {d.get('edge_count',0)} 边\")" 2>/dev/null # 7. 冲突和缺口 CONFLICTS=$(curl -s $BASE/api/v1/conflicts -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$CONFLICTS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"冲突: {d.get('count',0)} 待处理, {d.get('pending',0)} 待定\")" 2>/dev/null GAPS=$(curl -s $BASE/api/v1/gaps -H "X-API-Key: $API_KEY" 2>/dev/null) echo "$GAPS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"缺口: {d.get('open',0)} 未关闭\")" 2>/dev/null echo "=== 检查完成 ==="