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

33 lines
2.0 KiB
Python

#!/usr/bin/env python3
import paramiko
def run(host, user, pw, cmd, timeout=60):
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
HOSTS = [("10.88.0.4", "eric", "4669805"), ("10.88.0.5", "eric", "4669805")]
for host, user, pw in HOSTS:
print(f"\n{'#'*70}\n# {host}\n{'#'*70}")
cmds = [
("live_speed", "for pid in $(pgrep -f 'ffmpeg.*rtmps'); do echo PID=$pid; ps -p $pid -o %cpu,%mem,etime,cmd --no-headers | head -c 200; echo; timeout 3 tail -c 8000 /proc/$pid/fd/2 2>/dev/null | tr '\\r' '\\n' | grep speed= | tail -3; done"),
("proxychains", "pgrep -af proxychains; ps aux | grep proxychains | grep -v grep"),
("top_mem", "ps aux --sort=-%mem | head -15"),
("top_cpu", "ps aux --sort=-%cpu | head -15"),
("services", "systemctl is-active live-console shellcrash 2>/dev/null; docker ps --format '{{.Names}} {{.Status}}' 2>/dev/null | wc -l"),
("yt_proxy_test", "time curl -sS -m 15 -x socks5://127.0.0.1:7890 -o /dev/null -w 'yt_socks=%{http_code} spd=%{speed_download} time=%{time_total}\\n' https://a.rtmps.youtube.com/ 2>&1; time curl -sS -m 10 -o /dev/null -w 'douyin_pull=%{http_code} spd=%{speed_download} time=%{time_total}\\n' -H 'User-Agent: Mozilla/5.0' -H 'Referer: https://live.douyin.com/' 'http://pull-flv-l26.douyincdn.com/' 2>&1 | head -3"),
("wg", "ip -br a | grep -E 'wgeasy|wg0|enp'; wg show wgeasy 2>/dev/null | head -5"),
("lane_logs_mode", "grep -hE 'proxychains|push_proxy|stream copy|transcode|1080|1088|720' /home/eric/d2ypp2-src/.pm2/logs/youtube2__*-out.log 2>/dev/null | tail -12"),
]
for label, cmd in cmds:
print(f"\n--- {label} ---")
try:
print(run(host, user, pw, cmd)[:5000].encode("ascii", "backslashreplace").decode())
except Exception as ex:
print(ex)