diff --git a/scripts/cron_health_monitor.py b/scripts/cron_health_monitor.py index 32701435..1402e8ab 100644 --- a/scripts/cron_health_monitor.py +++ b/scripts/cron_health_monitor.py @@ -172,7 +172,33 @@ def main(): alerts.append(f"🔴 XMPP bridge检测失败: {e}") state[bridge_key] = {"last_alerted": datetime.now().timestamp()} - # ── 检查4:price_monitor数据新鲜度(直接查DB,不依赖job记录)─ + # ── 检查4:gateway LLM推理是否正常(发真实请求测响应时间) ─ + gateway_key = "gateway_down" + try: + import urllib.request, json, time + payload = json.dumps({ + "model": "position-analyst", + "messages": [{"role": "user", "content": "ok"}], + "max_tokens": 5 + }).encode() + req = urllib.request.Request("http://127.0.0.1:8643/v1/chat/completions", + data=payload, + headers={"Authorization": "Bearer hermes123", "Content-Type": "application/json"}) + t0 = time.time() + resp = urllib.request.urlopen(req, timeout=30) + elapsed = time.time() - t0 + data = json.loads(resp.read()) + usage = data.get("usage", {}) + tok = usage.get("total_tokens", 0) + if elapsed > 25 and is_new_alert(gateway_key, state): + alerts.append(f"🔴 gateway响应慢: {elapsed:.0f}s ({tok}tok)") + state[gateway_key] = {"last_alerted": datetime.now().timestamp()} + except Exception as e: + if is_new_alert(gateway_key, state): + alerts.append(f"🔴 gateway推理失败: {e}") + state[gateway_key] = {"last_alerted": datetime.now().timestamp()} + + # ── 检查5:price_monitor数据新鲜度(直接查DB,不依赖job记录)─ price_key = "price_stale" try: import sqlite3