sh2/d2ypp2/tools/check_host04_now.py
2026-06-14 10:41:48 -05:00

104 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""Quick remote check for 10.88.0.4 deployment and YouTube Pro status."""
from __future__ import annotations
import json
import sys
import paramiko
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
BASE = "/home/eric/d2ypp2-src"
def run(cmd: str, timeout: int = 60) -> str:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(HOST, username=USER, password=PASS, timeout=20)
_, stdout, stderr = client.exec_command(f"export LC_ALL=C.UTF-8; {cmd}", timeout=timeout)
out = (stdout.read() + stderr.read()).decode("utf-8", "replace")
client.close()
return out
def main() -> int:
checks: list[tuple[str, str]] = [
("hostname", "hostname"),
("health", "curl -sf -m 5 http://127.0.0.1:8001/health; echo"),
(
"web_root",
"curl -sS -m 8 -o /dev/null -w 'http_code=%{http_code} size=%{size_download}' http://127.0.0.1/; echo",
),
(
"console_built",
"curl -sf -m 8 http://127.0.0.1:8001/server_info | python3 -c \"import sys,json; d=json.load(sys.stdin); print('console_built=', d.get('console_built'))\"",
),
(
"ui_helpers",
f"grep -n 'proLanePrimaryTitle\\|proLaneStatusLabel' {BASE}/web-console/components/live-product/LiveYoutubeUnmannedView.tsx | head -5",
),
(
"backend_is_pushing",
f"grep -n 'is_pushing' {BASE}/src/process_runtime_status.py | tail -2",
),
(
"backend_ambiguous",
f"grep -n '_log_indicates_active_relay' {BASE}/src/douyin_source_display.py | head -2",
),
(
"web_out_mtime",
f"ls -la {BASE}/web-console/out/index.html {BASE}/web-console/out/_next/static/chunks/app/page-*.js 2>/dev/null | tail -3",
),
("uvicorn", "pgrep -af 'uvicorn web:app' | head -2"),
("youtube_procs", "pgrep -af 'youtube.py' | grep -v grep | head -8"),
("ffmpeg", "pgrep -af 'ffmpeg.*rtmps' | head -3"),
(
"process_monitor",
"""curl -sf -m 8 'http://127.0.0.1:8001/process_monitor?family=youtube' | python3 - <<'PY'
import json,sys
rows=json.load(sys.stdin).get('rows') or []
for r in rows[:8]:
print(
f"{r.get('pm2')}: business={r.get('business_status')} pushing={r.get('is_pushing')} "
f"display={r.get('source_display') or r.get('source_title') or '-'} label={r.get('label')}"
)
if not rows:
print('no youtube rows')
PY""",
),
(
"pro_channels",
"""curl -sf -m 8 'http://127.0.0.1:8001/hub/youtube_pro_channels' | python3 - <<'PY'
import json,sys
data=json.load(sys.stdin)
channels=data.get('channels') or []
print('channel_count=', len(channels))
for ch in channels[:8]:
print(f" id={ch.get('id')} name={ch.get('name')} pm2={ch.get('pm2Name')}")
PY""",
),
(
"recent_youtube_log",
f"tail -n 8 {BASE}/.pm2/logs/youtube2__ch_mp9mm36r_2wn0r-out.log 2>/dev/null || "
f"ls -1 {BASE}/.pm2/logs/*youtube*out.log 2>/dev/null | head -5",
),
(
"js_bundle_has_fix",
f"grep -l 'proLanePrimaryTitle\\|推流中' {BASE}/web-console/out/_next/static/chunks/app/page-*.js 2>/dev/null | head -1 | xargs -I{{}} sh -c 'echo bundle={{}}; grep -o proLanePrimaryTitle {{}} | head -1 || echo minified_no_symbol'",
),
]
for title, cmd in checks:
print(f"\n=== {title} ===")
try:
text = run(cmd)
print(text[:3000] if text else "(empty)")
except Exception as exc:
print(f"ERR: {exc}")
return 0
if __name__ == "__main__":
raise SystemExit(main())