#!/usr/bin/env python3 """Live streaming speed check on remote host.""" from __future__ import annotations import json import sys import paramiko HOST = "10.88.0.4" USER = "eric" PASS = "4669805" def run(client: paramiko.SSHClient, cmd: str, timeout: int = 60) -> str: _, stdout, stderr = client.exec_command(cmd, timeout=timeout, get_pty=True) out = stdout.read().decode("utf-8", "replace") err = stderr.read().decode("utf-8", "replace") return (out + err).strip() def main() -> int: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(HOST, username=USER, password=PASS, timeout=20) print("=== process_monitor ===") raw = run(client, "curl -sS -m 15 'http://127.0.0.1:8001/process_monitor?family=youtube'") try: data = json.loads(raw) for entry in data.get("entries", []): print( f"{entry.get('pm2')}: status={entry.get('process_status')} " f"biz={entry.get('business_status')} speed={entry.get('ffmpeg_speed')} " f"speed_low={entry.get('ffmpeg_speed_low')} pids={entry.get('ffmpeg_pids')}" ) note = entry.get("business_note") or "" if note: print(f" note: {note}") except json.JSONDecodeError: print(raw[:3000]) print("\n=== quality_guard ===") raw = run(client, "curl -sS -m 15 'http://127.0.0.1:8001/youtube/quality_guard'") try: q = json.loads(raw) print(json.dumps(q, ensure_ascii=False, indent=2)[:6000]) except json.JSONDecodeError: print(raw[:3000]) print("\n=== ffmpeg speed (sudo tail stderr) ===") print( run( client, f"echo '{PASS}' | sudo -S -p '' bash -lc " "\"for pid in $(pgrep -f 'ffmpeg.*rtmps://a.rtmps.youtube.com'); do " "echo PID=$pid; timeout 2 tail -c 4000 /proc/$pid/fd/2 2>/dev/null | tr '\\r' '\\n' | grep speed= | tail -2; done\"", timeout=30, ) ) print("\n=== youtube processes ===") print(run(client, "ps aux | grep 'd2ypp2-src/youtube.py' | grep -v grep")) print("\n=== active youtube configs fast_audio ===") print( run( client, "grep -H 'fast_audio\\|bitrate' /home/eric/d2ypp2-src/config/youtube.youtube2__*.ini 2>/dev/null", ) ) print("\n=== system load / mem ===") print(run(client, "uptime; free -h | head -2; nproc")) client.close() return 0 if __name__ == "__main__": raise SystemExit(main())