sh2/d2ypp2/tools/inspect_relay_log_host03.py
eric 278b48497e Add YouTube relay log tooling and optional hub service controls.
This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 05:10:09 -05:00

35 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Inspect relay log DB and PM2 log samples on host03."""
from __future__ import annotations
import json
import sys
import paramiko
HOST, USER, PASS = "10.88.0.3", "eric", "Xiao4669805"
BASE = "/opt/live/d2ypp"
def run(cmd: str, timeout: int = 180) -> str:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=20)
_, o, e = c.exec_command("export LC_ALL=C.UTF-8 LANG=C.UTF-8; " + cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace")
c.close()
return out
cmds = [
"curl -sS 'http://127.0.0.1:8001/hub/youtube/relay/sessions?process=youtube&limit=20' | python3 -m json.tool 2>/dev/null | head -120",
f"sqlite3 {BASE}/config/hub_state.sqlite \"SELECT id, anchor_name, datetime(started_at,'unixepoch','localtime'), datetime(ended_at,'unixepoch','localtime'), duration_seconds, source_url, stream_title FROM youtube_relay_sessions ORDER BY started_at DESC LIMIT 15\" 2>/dev/null",
"grep -E '开始推流到 YouTube|正在录制 1|推流已彻底停止|准备开始录制' /root/.pm2/logs/youtube-out.log 2>/dev/null | tail -30",
"grep -E '开始推流到 YouTube|正在录制 1' /root/.pm2/logs/youtube-out.log 2>/dev/null | head -15",
f"cat {BASE}/config/URL_config.youtube.ini 2>/dev/null | head -30",
"wc -l /root/.pm2/logs/youtube-out.log 2>/dev/null",
]
for cmd in cmds:
sys.stdout.buffer.write(f"\n=== {cmd[:100]} ===\n".encode())
sys.stdout.buffer.write(run(cmd)[:6000].encode("utf-8", "replace") + b"\n")