98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
|
|
BASE = "/home/eric/d2ypp2-src"
|
|
|
|
|
|
def run(cmd: str, timeout: int = 90) -> 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.strip()
|
|
|
|
|
|
def curl_json(path: str) -> tuple[int, object | str]:
|
|
raw = run(f"curl -sS -m 12 -w '\\n__HTTP__%{{http_code}}' 'http://127.0.0.1:8001{path}'")
|
|
if "__HTTP__" not in raw:
|
|
return 0, raw
|
|
body, code_s = raw.rsplit("__HTTP__", 1)
|
|
code = int(code_s.strip() or "0")
|
|
body = body.strip()
|
|
if not body:
|
|
return code, ""
|
|
try:
|
|
return code, json.loads(body)
|
|
except json.JSONDecodeError:
|
|
return code, body[:2000]
|
|
|
|
|
|
def main() -> int:
|
|
print("=== host ===")
|
|
print(run("hostname"))
|
|
|
|
print("\n=== is_pushing fix on disk ===")
|
|
print(run(f"grep -n 'is_pushing' {BASE}/src/process_runtime_status.py | tail -2"))
|
|
|
|
print("\n=== uvicorn ===")
|
|
print(run("pgrep -af 'uvicorn web:app' | head -2"))
|
|
|
|
print("\n=== ffmpeg pushing ===")
|
|
print(run("pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | head -3"))
|
|
|
|
code, data = curl_json("/process_monitor?family=youtube")
|
|
print(f"\n=== process_monitor http={code} ===")
|
|
if isinstance(data, dict):
|
|
rows = data.get("rows") or []
|
|
print("row_count", len(rows))
|
|
for row in rows:
|
|
print(
|
|
f" {row.get('pm2')}: business={row.get('business_status')} "
|
|
f"pushing={row.get('is_pushing')} label={row.get('label')} "
|
|
f"display={row.get('source_display') or row.get('source_title') or '-'}"
|
|
)
|
|
else:
|
|
print(data)
|
|
|
|
code, data = curl_json("/hub/youtube_pro_channels")
|
|
print(f"\n=== pro_channels http={code} ===")
|
|
if isinstance(data, dict):
|
|
for ch in (data.get("channels") or [])[:8]:
|
|
print(f" name={ch.get('name')} pm2={ch.get('pm2Name')}")
|
|
else:
|
|
print(data)
|
|
|
|
print("\n=== served page bundle ===")
|
|
print(run("curl -sS -m 8 http://127.0.0.1/ | grep -o 'page-[a-z0-9]*\\.js' | head -3"))
|
|
|
|
print("\n=== bundle contains new UI strings ===")
|
|
print(
|
|
run(
|
|
"python3 -c \"from pathlib import Path; import glob; "
|
|
f"files=glob.glob('{BASE}/web-console/out/_next/static/chunks/app/page-*.js'); "
|
|
"text=Path(files[0]).read_text('utf-8', errors='replace') if files else ''; "
|
|
"needles=['当前转播线路','抖音源','Pro relay status']; "
|
|
"[print(n, n in text) for n in needles]; "
|
|
"print('file', files[0] if files else 'none', 'size', len(text))\""
|
|
)
|
|
)
|
|
|
|
print("\n=== lane logs (last 2 lines each) ===")
|
|
print(run(f"for f in {BASE}/.pm2/logs/youtube2__*-out.log; do echo ---$f---; tail -n 2 $f; done"))
|
|
|
|
print("\n=== restart web if python module stale? ===")
|
|
print(run(f"stat -c '%y' {BASE}/src/process_runtime_status.py; ps -o lstart= -p $(pgrep -f 'uvicorn web:app' | head -1) 2>/dev/null"))
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|