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

104 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""Diagnose YT svc / shorts / live on dylive + dy."""
from __future__ import annotations
import json
import sys
import http.cookiejar
import urllib.request
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def call(method, url, body=None, opener=None, timeout=25):
data = None if body is None else json.dumps(body).encode()
req = urllib.request.Request(
url,
data=data,
method=method,
headers={"Content-Type": "application/json", "User-Agent": "curl/8"},
)
op = opener or urllib.request.build_opener()
try:
with op.open(req, timeout=timeout) as r:
raw = r.read().decode("utf-8", "replace")
return r.status, raw[:800]
except Exception as ex:
return getattr(ex, "code", None), str(ex)[:300]
def site(base: str, user="hackrobot", password="Xiao4669805@"):
print(f"\n===== {base} =====")
print("health", call("GET", f"{base}/api/health"))
print("health_detail", call("GET", f"{base}/api/health?detail=1"))
cj = http.cookiejar.CookieJar()
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
print("login", call("POST", f"{base}/api/auth/login", {"username": user, "password": password}, op))
for path in [
"/api/youtube-monitor/status",
"/api/shorts/status",
"/api/youtube/relay/status",
"/api/yt-long/status",
"/api/ops/host-metrics",
]:
st, body = call("GET", f"{base}{path}", opener=op, timeout=40)
print(path, st, body[:350].replace("\n", " "))
def ssh_host(label, host, port, user, password, sudo=False):
print(f"\n===== SSH {label} =====")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, port, user, password, timeout=40, allow_agent=False, look_for_keys=False)
def run(cmd, t=90):
if sudo:
cmd = f"echo '{password}' | sudo -S -p '' bash -lc {repr(cmd)}"
_, o, e = c.exec_command(cmd, timeout=t)
return (o.read() + e.read()).decode("utf-8", "replace")
print(run(
"systemctl is-active douyinweb-api douyinweb-yt douyinweb-web douyinweb-pb douyinweb-s3 2>/dev/null; "
"ss -ltn | grep -E ':8014|:8020|:8092|:8333|:4015' || true"
))
print("--- yt unit ---")
print(run("systemctl status douyinweb-yt --no-pager -l 2>/dev/null | head -40"))
print("--- yt journal ---")
print(run("journalctl -u douyinweb-yt -n 40 --no-pager 2>/dev/null"))
print("--- curl yt svc ---")
print(run(
"curl -sS -m 5 http://127.0.0.1:8020/health 2>&1 | head -c 300; echo; "
"curl -sS -m 5 http://127.0.0.1:8020/ 2>&1 | head -c 200; echo"
))
print("--- api health local ---")
print(run("curl -sS -m 8 'http://127.0.0.1:8014/api/health?detail=1' | head -c 600; echo"))
print("--- settings shorts/relay ---")
print(run(
"python3 - <<'PY'\n"
"import sqlite3\n"
"db='/opt/douyinWEB/backend/data/monitor.db'\n"
"con=sqlite3.connect(db)\n"
"keys=('shorts_enabled','youtube_relay_enabled','yt_long_enabled','monitor_enabled')\n"
"for k in keys:\n"
" r=con.execute('select value from settings where key=?',(k,)).fetchone()\n"
" print(k, r[0] if r else None)\n"
"print('shorts_channels', con.execute(\"select count(1) from shorts_channels\").fetchone() if False else 'n/a')\n"
"for t in ('shorts_channels','yt_assign_groups','yt_relay_states'):\n"
" try:\n"
" print(t, con.execute(f'select count(1) from {t}').fetchone()[0])\n"
" except Exception as e:\n"
" print(t, e)\n"
"PY"
))
print("--- procs ---")
print(run("ps -eo pid,etime,cmd | grep -E 'uvicorn|youtube|node.*8020|yt.svc|douyinweb' | grep -v grep | head -25"))
c.close()
site("https://dylive.nomadro.com")
site("https://dy.nomadro.com")
ssh_host("VPS/dylive", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
ssh_host("PHYS/dy", "107.173.30.245", 4014, "eric", "4669805", sudo=True)