88 lines
3.3 KiB
Python
88 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Compare streaming speed/config across 10.88.0.3/.4/.5."""
|
|
from __future__ import annotations
|
|
|
|
import paramiko
|
|
|
|
HOSTS = [
|
|
("10.88.0.3", "eric", "Xiao4669805"),
|
|
("10.88.0.4", "eric", "4669805"),
|
|
("10.88.0.5", "eric", "4669805"),
|
|
]
|
|
|
|
CMDS = [
|
|
("identity", "hostname; uname -m; nproc; free -h | grep Mem; uptime"),
|
|
(
|
|
"ffmpeg",
|
|
"ffmpeg -hide_banner -version 2>&1 | head -3; which ffmpeg; ls -la $(which ffmpeg) 2>/dev/null",
|
|
),
|
|
("hw_profile", "cat /home/eric/d2ypp2-src/config/hardware-profile.json 2>/dev/null | head -c 2500"),
|
|
("hardware_env", "cat /home/eric/d2ypp2-src/config/hardware.env 2>/dev/null"),
|
|
("pm2", "PM2_HOME=/home/eric/d2ypp2-src/.pm2 pm2 list 2>/dev/null | head -25"),
|
|
("ffmpeg_ps", "ps aux | grep -E 'ffmpeg.*rtmps' | grep -v grep"),
|
|
(
|
|
"speed_proc",
|
|
r"""for pid in $(pgrep -f 'ffmpeg.*rtmps://a.rtmps.youtube.com' 2>/dev/null); do
|
|
echo PID=$pid
|
|
timeout 2 cat /proc/$pid/fd/2 2>/dev/null | tr '\r' '\n' | grep -E 'speed=|stream copy|transcode|YouTube Live profile' | tail -5
|
|
done""",
|
|
),
|
|
("speed_api", "curl -sS -m 12 'http://127.0.0.1:8001/process_monitor?family=youtube' 2>/dev/null | head -c 4000"),
|
|
(
|
|
"youtube_ini",
|
|
"grep -H 'video_mode\\|fast_audio\\|bitrate' /home/eric/d2ypp2-src/config/youtube.youtube2__*.ini 2>/dev/null | head -20",
|
|
),
|
|
(
|
|
"code_hash",
|
|
"md5sum /home/eric/d2ypp2-src/douyin_youtube_ffplay.py /home/eric/d2ypp2-src/youtube.py 2>/dev/null",
|
|
),
|
|
("load", "top -bn1 | head -5; echo ffmpeg_count=$(pgrep -cf ffmpeg)"),
|
|
(
|
|
"proxy",
|
|
"curl -sS -m 5 -x socks5://127.0.0.1:7890 https://www.gstatic.com/generate_204 -w 'socks=%{http_code} time=%{time_total}\n' -o /dev/null 2>&1; "
|
|
"curl -sS -m 5 -x http://127.0.0.1:7894 https://www.gstatic.com/generate_204 -w 'http=%{http_code} time=%{time_total}\n' -o /dev/null 2>&1",
|
|
),
|
|
(
|
|
"recent_log",
|
|
"grep -hE 'speed=|stream copy|transcode|YouTube Live profile|hardware relay' /home/eric/d2ypp2-src/.pm2/logs/youtube2__*-out.log 2>/dev/null | tail -10",
|
|
),
|
|
(
|
|
"ffplay_re",
|
|
"grep -n '\\-re' /home/eric/d2ypp2-src/douyin_youtube_ffplay.py | head -8",
|
|
),
|
|
(
|
|
"static_ffmpeg",
|
|
"file $(which ffmpeg); ldd $(which ffmpeg) 2>&1 | head -3",
|
|
),
|
|
]
|
|
|
|
|
|
def q(host: str, user: str, pw: str, cmd: str, timeout: int = 45) -> str:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, username=user, password=pw, timeout=15)
|
|
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
c.close()
|
|
return out
|
|
|
|
|
|
def main() -> int:
|
|
for host, user, pw in HOSTS:
|
|
print(f"\n{'=' * 60}\nHOST {host}\n{'=' * 60}")
|
|
try:
|
|
for label, cmd in CMDS:
|
|
print(f"\n--- {label} ---")
|
|
try:
|
|
out = q(host, user, pw, cmd)
|
|
print(out[:4000].encode("ascii", "backslashreplace").decode())
|
|
except Exception as exc:
|
|
print(f"CMD_ERR: {exc}")
|
|
except Exception as exc:
|
|
print(f"CONNECT_FAIL: {exc}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|