douyinWEB/scripts/_diag_neko_loading.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

108 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
"""Diagnose neko loading forever: WS + WebRTC ports for 1 vs 5."""
from __future__ import annotations
import asyncio
import json
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
async def ws_probe(url: str) -> str:
try:
import websockets
except ImportError:
return "no websockets lib"
try:
async with asyncio.timeout(8):
async with websockets.connect(
url,
open_timeout=8,
close_timeout=3,
additional_headers={"Origin": "https://dy.nomadro.com"},
) as ws:
# try receive hello or ping
try:
msg = await asyncio.wait_for(ws.recv(), timeout=3)
return f"ok recv={str(msg)[:120]}"
except asyncio.TimeoutError:
return "ok connected (no msg)"
except TypeError:
try:
async with websockets.connect(url, open_timeout=8, extra_headers={"Origin": "https://dy.nomadro.com"}) as ws:
return "ok connected"
except Exception as e:
return f"fail {type(e).__name__}: {e}"
except Exception as e:
return f"fail {type(e).__name__}: {e}"
def ssh(h, p, u, pw):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(h, p, u, pw, timeout=45, allow_agent=False, look_for_keys=False)
return c
def run(c, cmd, t=90):
_, o, e = c.exec_command(cmd, timeout=t)
return (o.read() + e.read()).decode("utf-8", "replace")
async def main():
print("=== WS probes ===")
for path in ["/neko/1/", "/neko/5/", "/neko/5/ws", "/neko/1/ws"]:
# neko uses various ws paths - try common
url = "wss://dy.nomadro.com" + path
print(path, await ws_probe(url))
g = ssh("107.173.30.245", 4014, "eric", "4669805")
print(
"\n=== PHYSICAL neko env/ports ===\n",
run(
g,
r"""
echo '4669805' | sudo -S -p '' bash -lc '
for i in 1 5 6; do
echo === neko-$i ===
docker inspect douyinweb-neko-$i --format "{{range .Config.Env}}{{println .}}{{end}}" | grep -iE "NEKO_|NAT|EPR|PORT|PROXY" | head -40
docker port douyinweb-neko-$i
done
echo === listen udp related ===
ss -ulnp | grep -E "5200|5210|5230|5240|5250|5260" | head -40
echo === nat1to1 cache ===
cat /opt/douyinWEB/backend/data/neko/nat1to1.txt 2>/dev/null || true
grep -E "NEKO_NAT|NAT1TO1" /etc/systemd/system/douyinweb-api.service 2>/dev/null || true
'
""",
),
)
g.close()
v = ssh("107.173.30.245", 22, "root", "Xiao4669805")
print(
"\n=== OVERSEAS DNAT / UFW ===\n",
run(
v,
r"""
echo --- iptables DNAT neko ---
iptables -t nat -S | grep -E '5200|5210|5230|5240|5250|5260|920' | head -60
echo --- ufw ---
ufw status | grep -E '5200|521|523|524|525|526|920' | head -40
echo --- compose webrtc hint ---
# probe UDP not easy; check TCP mux
for p in 52300 52301 52303 52304 52305; do
timeout 2 bash -c "echo >/dev/tcp/10.8.0.2/$p" 2>/dev/null && echo "tcp $p open" || echo "tcp $p closed/filtered"
done
""",
),
)
v.close()
if __name__ == "__main__":
asyncio.run(main())