119 lines
3.6 KiB
Python
119 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Diagnose dy.nomadro.live pressure / hang. No config changes."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import ssl
|
|
import sys
|
|
import time
|
|
import urllib.request
|
|
from http.cookiejar import CookieJar
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
CTX = ssl.create_default_context()
|
|
|
|
|
|
def connect():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
"108.174.50.68",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=180,
|
|
)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", i, e, flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit("ssh_fail")
|
|
|
|
|
|
c = connect()
|
|
_i, o, e = c.exec_command(
|
|
r"""
|
|
set +e
|
|
echo '=== host ==='
|
|
hostname; uptime; free -m | head -2
|
|
echo
|
|
echo '=== load / iowait ==='
|
|
vmstat 1 3
|
|
echo
|
|
echo '=== top cpu/mem ==='
|
|
ps aux --sort=-%cpu | head -12
|
|
echo '---'
|
|
ps aux --sort=-%mem | head -12
|
|
echo
|
|
echo '=== app units ==='
|
|
systemctl is-active douyinweb-api douyinweb-web
|
|
ps -o pid,stat,etime,%cpu,%mem,cmd -C python,uvicorn,node,next-server 2>/dev/null | head -20
|
|
pgrep -af 'uvicorn app.main|next-server' | head -10
|
|
echo
|
|
echo '=== ports ==='
|
|
ss -lntp | grep -E ':8014|:4015|:443' || true
|
|
echo
|
|
echo '=== local latency ==='
|
|
for i in 1 2 3; do
|
|
curl -sS -m 8 -o /dev/null -w "health_$i:%{http_code} t=%{time_total}\n" http://127.0.0.1:8014/api/health || echo health_$i:FAIL
|
|
curl -sS -m 12 -o /dev/null -w "home_$i:%{http_code} t=%{time_total}\n" http://127.0.0.1:4015/ || echo home_$i:FAIL
|
|
done
|
|
echo
|
|
echo '=== neko ==='
|
|
docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort -V
|
|
for n in $(docker ps --filter name=douyinweb-neko --format '{{.Names}}'); do
|
|
docker stats --no-stream --format '{{.Name}} cpu={{.CPUPerc}} mem={{.MemUsage}}' "$n"
|
|
done
|
|
echo
|
|
echo '=== disk ==='
|
|
df -h / /opt 2>/dev/null | head -5
|
|
echo
|
|
echo '=== api journal (errors) ==='
|
|
journalctl -u douyinweb-api -n 30 --no-pager 2>/dev/null | tail -30
|
|
echo
|
|
echo '=== relay settings ==='
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app import db, yt_assign_db
|
|
cfg=db.get_settings_map()
|
|
print('relay', cfg.get('youtube_relay_enabled'), 'slot', cfg.get('youtube_relay_time_slot_mode'), 'excl', cfg.get('youtube_relay_exclusive_live'))
|
|
en=[(g.get('name'), g.get('neko_instance_id'), g.get('neko_enabled')) for g in yt_assign_db.list_groups(include_urls=False, include_secret=False) if g.get('neko_enabled')]
|
|
print('neko_enabled', en)
|
|
PY
|
|
echo DY_DIAG_DONE
|
|
""",
|
|
timeout=120,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
print("\n=== public probe ===", flush=True)
|
|
jar = CookieJar()
|
|
opener = urllib.request.build_opener(
|
|
urllib.request.HTTPCookieProcessor(jar),
|
|
urllib.request.HTTPSHandler(context=CTX),
|
|
)
|
|
t0 = time.time()
|
|
try:
|
|
with opener.open(urllib.request.Request("https://dy.nomadro.live/", method="GET"), timeout=25) as r:
|
|
body = r.read(2000)
|
|
print("home", r.status, f"t={time.time()-t0:.2f}s", "bytes", len(body), flush=True)
|
|
except Exception as e:
|
|
print("home ERR", e, f"t={time.time()-t0:.2f}s", flush=True)
|
|
|
|
t0 = time.time()
|
|
try:
|
|
with opener.open(urllib.request.Request("https://dy.nomadro.live/api/health"), timeout=20) as r:
|
|
print("health", r.status, f"t={time.time()-t0:.2f}s", r.read(200), flush=True)
|
|
except Exception as e:
|
|
print("health ERR", e, f"t={time.time()-t0:.2f}s", flush=True)
|
|
|
|
print("DONE", flush=True)
|