douyinWEB/scripts/_diag_neko_lag.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

88 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
"""Quick Neko Chrome lag diagnostics on physical guest."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
REMOTE = r'''
import json, subprocess
def sh(cmd, t=60):
r=subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=t)
return ((r.stdout or "")+(r.stderr or "")).strip()
print("=== host resources ===")
print(sh("nproc; free -h | head -2; uptime; df -h / | tail -1"))
print(sh("docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}' | head -20"))
print("\n=== running neko ===")
print(sh("docker ps --format '{{.Names}}\t{{.Status}}\t{{.Ports}}' | grep neko | sort"))
print("\n=== neko env video/proxy (1,5,6) ===")
for i in (1,5,6):
name=f"neko-{i}"
out=sh(f"docker inspect {name} --format '{{{{range .Config.Env}}}}{{{{println .}}}}{{{{end}}}}' 2>/dev/null")
if not out:
print(i, "missing"); continue
keys=("NEKO_DESKTOP_SCREEN","NEKO_MAX_FPS","NEKO_VIDEO_BITRATE","NEKO_WEBRTC_EPR",
"NEKO_BROWSER_PROXY","NEKO_WEBRTC_NAT1TO1","NEKO_MEMBER_MULTIHOST")
print(f"--- {name} ---")
for line in out.splitlines():
for k in keys:
if line.startswith(k+"="):
print(line)
print("\n=== chrome inside 5 ===")
print(sh("docker exec neko-5 bash -lc 'supervisorctl status; ps -eo pid,pcpu,pmem,rss,cmd --sort=-pcpu | head -12' 2>/dev/null | head -25"))
print("\n=== proxy latency from host + container5 ===")
print(sh("curl -sS -o /dev/null -w 'host_proxy_yt=%{http_code} t=%{time_total}\\n' --max-time 20 -x http://127.0.0.1:7890 https://www.youtube.com/ || echo fail"))
print(sh("docker exec neko-5 bash -lc 'curl -sS -o /dev/null -w \"ctr_proxy_yt=%{http_code} t=%{time_total}\\\\n\" --max-time 20 -x http://host.docker.internal:7890 https://www.youtube.com/' 2>/dev/null || echo ctr_fail"))
print("\n=== compose defaults snippet ===")
print(sh("grep -nE 'DESKTOP_SCREEN|MAX_FPS|VIDEO_BITRATE|shm_size|BROWSER_PROXY' /opt/douyinWEB/backend/data/neko/docker-compose.yml | head -40"))
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=50,
banner_timeout=100,
allow_agent=False,
look_for_keys=False,
)
break
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2)
else:
raise SystemExit("ssh fail")
sftp = c.open_sftp()
with sftp.file("/tmp/_neko_lag.py", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command(
f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_neko_lag.py",
timeout=120,
)
print((o.read() + e.read()).decode("utf-8", "replace")[-15000:], flush=True)
c.close()
if __name__ == "__main__":
main()