Files
memoryweave/scripts/daily-check.sh
T
小唯 b2a016e90f fix(metrics): t_c70f385c 指标口径修复 — recall_hit_rate 退役 + gap_closure_rate 断言 + 最小样本门 N=20
- recall_hit_rate 退役:分子原为 core.go 的 len(results)>0(恒=1、无区分度),
  「返回且被使用」语义已由 recall_usefulness_rate 承担(207 样本 0.98)。
  Metrics()/distributed/metrics-gauge/executor/tuning/CLI/daily-check 全链移除该键。
- gap_closure_rate 统一为「缺口个数」口径:Close() 加 !g.Closed 守卫(与 RecordHit 一致),
  根治同一缺口重复关闭导致 ClosedGaps 虚增、越界 4.5;Metrics() 加越界断言 gapRate>1 → -1。
- 所有率类指标加最小样本门 minRateSamples=20:样本<20 ⇒ -1 + valid=0,
  杜绝 auto_resolve_rate 2 样本判满分。
- 测试:metrics_retire_regression_test.go 用生产同款计数复现改前/改后 JSON;
  selfoptimize 全套通过。
2026-10-17 20:32:34 +08:00

68 lines
3.2 KiB
Bash
Executable File
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.
#!/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', 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 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 "=== 检查完成 ==="