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

97 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Diagnose dylive.nomadro.com /youtube ERR_FAILED."""
from __future__ import annotations
import socket
import ssl
import sys
import time
import urllib.error
import urllib.request
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
print("=== local DNS/TCP ===", flush=True)
try:
ips = socket.getaddrinfo("dylive.nomadro.com", 443, type=socket.SOCK_STREAM)
print("resolve", sorted({x[4][0] for x in ips}))
except Exception as e:
print("dns_fail", e)
for host, port in [("dylive.nomadro.com", 443), ("107.173.30.245", 443), ("107.173.30.245", 80)]:
s = socket.socket()
s.settimeout(5)
try:
s.connect((host, port))
print(f"tcp {host}:{port} OK")
except Exception as e:
print(f"tcp {host}:{port} FAIL {e}")
finally:
s.close()
ctx = ssl.create_default_context()
for url in (
"https://dylive.nomadro.com/",
"https://dylive.nomadro.com/youtube",
"https://dylive.nomadro.com/api/health",
"http://107.173.30.245/",
):
try:
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=15, context=ctx if url.startswith("https") else None) as r:
print(url, r.status, r.getheader("content-type"), "len", r.headers.get("content-length"))
except Exception as e:
print(url, "FAIL", type(e).__name__, e)
print("\n=== SSH host ===", flush=True)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=40,
allow_agent=False,
look_for_keys=False,
banner_timeout=180,
)
break
except Exception as e:
print("ssh_retry", i, e, flush=True)
time.sleep(2)
else:
raise SystemExit("ssh fail")
_i, o, e = c.exec_command(
r"""
set +e
echo '--- load/mem ---'
uptime
free -h | head -2
echo '--- units ---'
systemctl is-active caddy douyinweb-api douyinweb-web 2>/dev/null
systemctl --failed --no-pager 2>/dev/null | head -20
echo '--- listen ---'
ss -lntp | grep -E ':443|:80|:4015|:8014' | head -20
echo '--- curl local ---'
curl -sS -m 5 -o /dev/null -w 'loop_web:%{http_code}\n' http://127.0.0.1:4015/youtube || echo loop_web_fail
curl -sS -m 5 -o /dev/null -w 'loop_api:%{http_code}\n' http://127.0.0.1:8014/api/health || echo loop_api_fail
curl -sS -m 8 -o /dev/null -w 'caddy_https:%{http_code}\n' -k https://127.0.0.1/youtube -H 'Host: dylive.nomadro.com' || echo caddy_fail
curl -sS -m 8 -o /dev/null -w 'public:%{http_code}\n' https://dylive.nomadro.com/youtube || echo public_fail
echo '--- journal ---'
journalctl -u douyinweb-web -u douyinweb-api -u caddy --since '30 min ago' --no-pager 2>/dev/null | tail -60
echo '--- docker neko mem ---'
docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort
docker stats --no-stream --format '{{.Name}} {{.MemUsage}}' 2>/dev/null | grep neko | head
""",
timeout=90,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
print("DONE")