douyinWEB/scripts/_cmp_dy_dylive_cpu.py
2026-09-13 22:10:49 -05:00

73 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Compare dy vs dylive CPU/ffmpeg/neko — read only."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "Xiao4669805"
HOSTS = [
("dy", "108.174.50.68"),
("dylive", "107.173.30.245"),
]
CMD = r"""
echo HOST=$(hostname)
echo UPTIME=$(uptime)
echo CORES=$(nproc)
free -h | head -2
echo '---TOP---'
ps -eo pcpu,pmem,rss,comm,args --sort=-pcpu | head -18
echo '---FFMPEG---'
pgrep -a ffmpeg 2>/dev/null | while read -r line; do
pid=$(echo "$line" | awk '{print $1}')
cpu=$(ps -p "$pid" -o pcpu=,rss= 2>/dev/null)
# extract input url quality hint
echo "PID $pid CPU/RSS $cpu"
echo "$line" | tr ' ' '\n' | grep -E '_uhd|_hd|_sd|ORIGIN|rtmps|yt_long|clips/' | head -8
echo '---'
done
echo ffmpeg_n=$(pgrep -c ffmpeg 2>/dev/null || echo 0)
echo '---NEKO---'
docker ps --filter name=neko --format '{{.Names}} {{.Status}}' 2>/dev/null
docker stats --no-stream --format '{{.Name}} cpu={{.CPUPerc}} mem={{.MemUsage}}' 2>/dev/null | grep neko || true
echo '---API---'
ps -eo pcpu,pmem,rss,args | grep -E 'uvicorn app.main|next-server' | grep -v grep
echo '---LOADSRC---'
# soft decode clue: threads / preset in ffmpeg
pgrep -a ffmpeg 2>/dev/null | grep -oE '\-threads [0-9]+|\-preset [a-z0-9]+|\-b:v [^ ]+|\-vf [^ ]+' | head -40
"""
def connect(host):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(host, 22, "root", PASS, timeout=25, allow_agent=False, look_for_keys=False)
return c
except Exception as e:
print(f"ssh {host} fail {e}", flush=True)
time.sleep(1 + i)
raise SystemExit(f"ssh_fail {host}")
def main():
for name, host in HOSTS:
print(f"\n########## {name} {host} ##########", flush=True)
c = connect(host)
_i, o, e = c.exec_command(CMD, timeout=45)
print(o.read().decode("utf-8", "replace"), flush=True)
err = e.read().decode("utf-8", "replace")
if err.strip():
print("[stderr]", err[:500], flush=True)
c.close()
print("DONE", flush=True)
if __name__ == "__main__":
main()