73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import time
|
|
|
|
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 main() -> int:
|
|
for attempt in range(1, 21):
|
|
health = run("curl -sf -m 4 http://127.0.0.1:8001/health; echo")
|
|
if '"status":"ok"' in health or '"status": "ok"' in health:
|
|
print(f"health ok (attempt {attempt})")
|
|
break
|
|
print(f"waiting health attempt {attempt}: {health[:120]}")
|
|
time.sleep(2)
|
|
else:
|
|
print("health failed")
|
|
print(run(f"echo {PASS!r} | sudo -S -p '' systemctl status live-console.service --no-pager"))
|
|
|
|
raw = run("curl -sS -m 12 'http://127.0.0.1:8001/process_monitor?family=youtube'")
|
|
print("\n=== process_monitor ===")
|
|
try:
|
|
data = json.loads(raw)
|
|
entries = data.get("entries") or []
|
|
print("entries", len(entries))
|
|
for row in entries:
|
|
print(
|
|
f" {row.get('pm2')}: business={row.get('business_status')} pushing={row.get('is_pushing')} "
|
|
f"label={row.get('label')} display={row.get('source_display') or row.get('source_title') or '-'}"
|
|
)
|
|
except json.JSONDecodeError:
|
|
print(raw[:2500])
|
|
|
|
print("\n=== served bundle ===")
|
|
print(run("curl -sS -m 8 http://127.0.0.1/ | grep -o 'page-[a-z0-9]*\\.js' | head -1"))
|
|
|
|
print("\n=== chunk string hits ===")
|
|
print(
|
|
run(
|
|
"python3 -c \"from pathlib import Path; import glob; "
|
|
f"hits=[]; "
|
|
f"files=glob.glob('{BASE}/web-console/out/_next/static/chunks/**/*.js', recursive=True); "
|
|
"needles=['Douyin','Current relay lane','Pro relay status','Waiting source','Pushing']; "
|
|
"exec('for p in files:\\n t=Path(p).read_text(\\\"utf-8\\\",errors=\\\"replace\\\")\\n for n in needles:\\n if n in t: hits.append((n,p))'); "
|
|
"[print(h) for h in hits[:12]]; print('files',len(files))\""
|
|
)
|
|
)
|
|
|
|
print("\n=== ffmpeg / youtube ===")
|
|
print(run("pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | wc -l"))
|
|
print(run("pgrep -af 'youtube.py' | grep -v pgrep"))
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|