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

127 lines
4.3 KiB
Python

#!/usr/bin/env python3
"""Diagnose ALL dylive neko containers: Up/Created, chrome, Tampermonkey, CDP."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(10):
try:
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=50,
allow_agent=False,
look_for_keys=False,
banner_timeout=180,
)
break
except Exception as e:
print("retry", i, e, flush=True)
time.sleep(2 + i)
else:
raise SystemExit("ssh fail")
_i, o, e = c.exec_command(
r"""
set +e
echo '======== ALL neko containers ========'
docker ps -a --filter name=douyinweb-neko --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | sort
echo
echo '======== Caddy /neko routes sample ========'
grep -nE 'handle_path /neko/|reverse_proxy.*92' /etc/caddy/sites/*dylive* 2>/dev/null | head -40
ls /etc/caddy/sites/ 2>/dev/null | head
echo
echo '======== per-instance deep ========'
for name in $(docker ps -a --format '{{.Names}}' | grep '^douyinweb-neko-' | sort -V); do
echo
echo "----- $name -----"
st=$(docker inspect -f '{{.State.Status}} OOM={{.State.OOMKilled}} Exit={{.State.ExitCode}}' "$name" 2>/dev/null)
echo "state: $st"
# only exec if running
if docker inspect -f '{{.State.Running}}' "$name" 2>/dev/null | grep -q true; then
docker exec "$name" sh -c '
echo "supervisor:"
supervisorctl status 2>/dev/null | head -10
echo "chrome_cdp:"
curl -sS -m 2 http://127.0.0.1:9222/json/version 2>/dev/null | head -c 120; echo
echo "tampermonkey_ext:"
ls -d /home/neko/.config/google-chrome/*/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo 2>/dev/null | head -5
ls /home/neko/.config/google-chrome/Default/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo 2>/dev/null | head -5
# Preferences LoadExtension / disable
python3 - <<"PY"
import json,os,glob
prefs=glob.glob("/home/neko/.config/google-chrome/*/Preferences")+glob.glob("/home/neko/.config/google-chrome/Default/Preferences")
for p in prefs[:3]:
try:
d=json.load(open(p,encoding="utf-8"))
except Exception as e:
print("prefs_err",p,e); continue
ext=(d.get("extensions") or {})
settings=ext.get("settings") or {}
tm=[k for k in settings if "dhdgffkkebhmkfjojejmpbldmpobfkfo" in k or k.startswith("dhdg")]
print("prefs",p,"tm_keys",tm[:3] or "NONE")
for k in list(settings.keys()):
if "dhdgff" in k or "tamper" in k.lower():
s=settings[k]
print(" ",k,"state",s.get("state"),"path",str(s.get("path") or "")[:60],"manifest",bool(s.get("manifest")))
# also check disable list
cmd=str((d.get("browser") or {}).get("enabled_labs_experiments") or "")
PY
echo "chrome_cmdline_ext:"
for p in /proc/[0-9]*; do
cmd=$(tr "\0" " " < "$p/cmdline" 2>/dev/null)
case "$cmd" in
*remote-debugging-port=9222*)
echo "$cmd" | tr " " "\n" | grep -iE "load-extension|disable-extensions|jitless|user-dir" | head -20
break
;;
esac
done
echo "tm_seed_mount:"
ls -la /etc/neko/tampermonkey-seed 2>/dev/null | head -5
ls /opt 2>/dev/null | head -1
' 2>&1 | head -80
else
echo "(not running — skip exec)"
# show mounts / create reason
docker inspect -f 'Created={{.Created}} Image={{.Config.Image}}' "$name" 2>/dev/null
fi
done
echo
echo '======== assign map neko ids ========'
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app import yt_assign_db
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
print(f"{g.get('name')[:24]:24} neko={g.get('neko_instance_id')} en={g.get('neko_enabled')} cat={g.get('category')}")
PY
echo
echo '======== public neko/2 probe ========'
curl -sS -m 8 -o /dev/null -w 'neko2:%{http_code} redir=%{redirect_url}\n' https://dylive.nomadro.com/neko/2/ || echo fail
curl -sS -m 5 -o /dev/null -w 'local9201:%{http_code}\n' http://127.0.0.1:9201/ || echo local_fail
ss -lntp | grep -E ':920[0-9]|:921[0-9]' | head -30
echo
echo '======== mem ========'
free -h | head -2
docker stats --no-stream --format 'table {{.Name}}\t{{.MemUsage}}\t{{.CPUPerc}}' 2>/dev/null | grep neko | head -20
""",
timeout=300,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
print("DONE")