From 0793162bbfd07c6a005dce12cb9044ccc7f7b0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Wed, 8 Jul 2026 10:25:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E6=A3=80=E5=8A=A0=E7=AC=AC4?= =?UTF-8?q?=E9=A1=B9=E2=80=94=E2=80=94gateway=E5=AE=9E=E9=99=85LLM?= =?UTF-8?q?=E6=8E=A8=E7=90=86=E6=A3=80=E6=B5=8B(=E5=8F=91ok=E2=86=925tok)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/cron_health_monitor.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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