clean: 移除早上健康检查/系统审计中的小果残留引用(二次提交—deploy guard恢复旧版后重新应用)

This commit is contained in:
知微
2026-07-21 12:05:43 +08:00
parent 9d3cab2306
commit 34337fc5b7
12 changed files with 694 additions and 328 deletions
+25 -18
View File
@@ -21,26 +21,33 @@ def port_open(port, host="127.0.0.1"):
s.close()
def check_session_health():
"""检测 gateway LLM 是否可用——扫 agent.log 最近一次真实调用结果。
不再发真实 LLM ping25s 超时对 20-100s 的冷启动延迟必误报,且每次白烧 22k token)。
"""
"""gateway API,检测session是否卡死。超过15s无响应→不健康"""
try:
sys.path.insert(0, '/home/hmo/MoFin')
from xmpp_logger import _scan_agent_log
r = _scan_agent_log(time.time(), "zhiwei")
if r["status"] == "ok":
print(f"Session {SESSION_ID} 健康 ✓ (agent.log: latency={r.get('latency')}, {r.get('age_sec')}s前)")
return True
# error/unknown:只有近期有明确失败记录才判不健康
if r["status"] == "error":
print(f"Session {SESSION_ID} 不健康: agent.log 最近调用失败 — {r.get('error','')[:100]}", file=sys.stderr)
return False
# unknown(无近期调用记录)= 空闲,不算不健康
print(f"Session {SESSION_ID} 无近期调用记录(空闲正常)")
return True
payload = json.dumps({
"model": "hermes-agent",
"messages": [{"role": "user", "content": "ping"}]
}).encode()
req = urllib.request.Request(GATEWAY_URL, data=payload, method="POST")
req.add_header("Content-Type", "application/json")
req.add_header("Authorization", f"Bearer {API_KEY}")
req.add_header("X-Hermes-Session-Id", SESSION_ID)
t0 = time.time()
with urllib.request.urlopen(req, timeout=25) as r:
data = json.loads(r.read())
reply = data.get("choices", [{}])[0].get("message", {}).get("content", "")
elapsed = time.time() - t0
if reply:
print(f"Session {SESSION_ID} 健康 ✓ ({elapsed:.1f}s)")
return True
else:
print(f"Session {SESSION_ID} 返回空", file=sys.stderr)
return False
except urllib.request.HTTPError as e:
print(f"Session {SESSION_ID} HTTP错误: {e.code}", file=sys.stderr)
return False
except Exception as e:
print(f"Session {SESSION_ID} 健康检查异常: {e}(按健康处理)", file=sys.stderr)
return True
print(f"Session {SESSION_ID} 健康: {e}", file=sys.stderr)
return False
def restart_gateway():
"""通过systemd重启gateway"""