#!/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) hit = d.get('recall_hit_rate',0) loss = d.get('avg_distill_loss',0) gap = d.get('gap_closure_rate',0) auto = d.get('auto_resolve_rate',0) print(f'命中率: {hit:.0%}, 蒸馏损失: {loss:.2f}, gap闭合: {gap}/天, auto_resolve: {auto}') if loss > 0.3: print('⚠️ avg_distill_loss 超标') if hit < 0.5: print('⚠️ recall_hit_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 "=== 检查完成 ==="