douyinWEB/scripts/_probe_edge_catalog_studio.py
2026-09-13 22:10:49 -05:00

91 lines
3.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Check edge catalog studio payload + hub relay thread state."""
from __future__ import annotations
import json
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
VPS = ("107.173.30.245", 22, "root", "Xiao4669805")
PHYS = ("107.173.30.245", 4014, "eric", "4669805")
def run(host, port, user, pwd, cmd, t=60):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, port, user, pwd, timeout=25, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(cmd, timeout=t)
out = (o.read() + e.read()).decode("utf-8", "replace")
c.close()
return out
def main():
print("=== EDGE: studio snap for ops:1 + catalog dry ===")
print(
run(
*PHYS,
r"""cd /opt/douyinWEB/backend && python3 - <<'PY'
import time, json
from app import youtube_neko as yn
from app import ops_neko
from app import ops_neko_db
print('peer', ops_neko_db.peer_status())
# memory refs on edge
refs=sorted((yn._studio_latest_by_ref or {}).keys())
print('edge_memory_refs', refs)
for k in refs:
if 'ops' in k or k in ('1','ops:1','ops-1'):
ev=yn._studio_latest_by_ref[k]
age=time.time()-float(ev.get('received_at') or 0)
p=ev.get('payload') if isinstance(ev.get('payload'),dict) else {}
print(' ', k, 'age', round(age,1), 'status', p.get('live_status'), 'url', str(p.get('url') or '')[:80])
snap=yn.studio_snapshot_for_ref('ops:1', max_age_sec=180)
print('edge_snap_ops1', json.dumps({k:snap.get(k) for k in ('live_page_open','on_air','live_status','url','age_sec','received_at','detect_source')}, ensure_ascii=False))
# What would catalog send?
studio=snap if (snap.get('received_at') or snap.get('on_air') or snap.get('live_page_open')) else None
print('catalog_would_send_studio', studio is not None)
if studio:
print(' keys', list(studio.keys())[:20])
PY""",
50,
)
)
print("=== VPS: relay state + recent journal for group ===")
print(
run(
*VPS,
r"""cd /opt/douyinWEB/backend && python3 - <<'PY'
import sqlite3, time, json
con=sqlite3.connect('data/monitor.db')
con.row_factory=sqlite3.Row
gid='3fb8cbf7-2180-45bc-99f0-836169f0bf97'
row=con.execute('select * from yt_relay_states where group_id=?',(gid,)).fetchone()
d=dict(row) if row else {}
print('status', d.get('status'), 'error', d.get('error'), 'ffmpeg', d.get('ffmpeg_pid'), 'updated_age', round(time.time()-float(d.get('updated_at') or 0),1))
log=str(d.get('recent_log') or '')
print('--- last 30 log lines ---')
print('\n'.join(log.strip().splitlines()[-30:]))
# sample age ops:1
s=con.execute("select ts, live_page_open, on_air, live_status from yt_studio_samples where neko_ref='ops:1' order by ts desc limit 1").fetchone()
if s:
print('hub_db_ops1_age', round(time.time()-float(s['ts']),1), 'open', s['live_page_open'], 'on_air', s['on_air'], 'st', s['live_status'])
PY
journalctl -u douyinweb-api --since '5 min ago' --no-pager 2>/dev/null | grep -iE 'relay|ffmpeg|ops.neko|3fb8|streetfood|wait|ready|gate|invalid' | tail -40
""",
50,
)
)
if __name__ == "__main__":
main()