fix(health): drop live LLM ping — scan agent.log instead (38s -> 0.1s)

Every /api/xmpp/health fetch ran a real LLM call (22k token system prompt
each). Dashboard refreshes every 10s -> thousands of paid LLM calls/day,
plus 38s latency hanging the health tab on '加载中...'.

LLM health is now derived from the gateway's own agent.log (zero cost,
more accurate than synthetic ping — real traffic results):
- last 'API call #N latency=Xs' -> ok
- last 'API call failed ... HTTP 429...' -> error with summary
- health() runtime 38s -> 0.1s; endpoint 38s -> 0.097s
This commit is contained in:
hmo
2026-07-20 00:21:49 +08:00
parent 058c42ce27
commit 2de527b883
2 changed files with 78 additions and 14 deletions
+20
View File
@@ -0,0 +1,20 @@
import ast, sys
for p in ['/home/hmo/MoFin/xmpp_logger.py']:
try:
ast.parse(open(p).read())
print('SYNTAX OK:', p)
except SyntaxError as e:
print('SYNTAX ERROR:', p, e)
sys.exit(1)
sys.path.insert(0, '/home/hmo/MoFin')
import xmpp_logger as x
import time, json
print('== _scan_agent_log ==')
print(json.dumps(x._scan_agent_log(time.time()), ensure_ascii=False))
print('== health (no LLM ping) ==')
import time as t
t0 = t.time()
h = x.health()
print(f'took {t.time()-t0:.1f}s')
print('llm_provider:', h.get('llm_provider'))
print('status:', h.get('status'))