# -*- coding: utf-8 -*- """Diagnose neko/7 Chrome only — no restart, no other instances.""" from __future__ import annotations import json import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") PASS = "4669805" IDX = 7 NAME = f"douyinweb-neko-{IDX}" def ssh(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(10): try: c.connect( "107.173.30.245", 4014, "eric", PASS, timeout=45, banner_timeout=120, allow_agent=False, look_for_keys=False, ) return c except Exception as ex: print("ssh", i, type(ex).__name__, flush=True) time.sleep(2) raise SystemExit("ssh fail") def run(c, cmd, timeout=60): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace") def main() -> int: c = ssh() print("=== container ===", flush=True) print( run( c, f"docker ps -a --filter name={NAME} --format '{{{{.Names}}}} {{{{.Status}}}} {{{{.Ports}}}}'; " f"docker inspect {NAME} --format 'RestartCount={{{{.RestartCount}}}} OOM={{{{.State.OOMKilled}}}} Health={{{{.State.Health.Status}}}}' 2>/dev/null; " f"curl -sS -m 5 -o /dev/null -w 'neko_http:%{{http_code}}\\n' http://127.0.0.1:920{IDX}/ 2>/dev/null || " f"curl -sS -m 5 -o /dev/null -w 'neko_http:%{{http_code}}\\n' http://127.0.0.1:$((9200+{IDX}-1))/ ", ), flush=True, ) print("=== supervisor / chrome ===", flush=True) print( run( c, f"docker exec {NAME} bash -lc '" "supervisorctl status 2>/dev/null || true; " "ps aux | grep -E \"[c]hrome|[c]hromium|[n]eko\" | head -40; " "free -m | head -3; " "df -h / | tail -1" "'", timeout=40, ), flush=True, ) print("=== CDP tabs ===", flush=True) print( run( c, f"docker exec {NAME} python3 - <<'PY'\n" "import json,urllib.request\n" "try:\n" " tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=5).read().decode())\n" "except Exception as e:\n" " print('CDP_FAIL',e); raise SystemExit(0)\n" "print('tab_count',len(tabs))\n" "for t in tabs:\n" " u=(t.get('url') or '')[:160]; title=(t.get('title') or '')[:80]\n" " print('-', t.get('type'), '|', title, '|', u)\n" "PY", timeout=30, ), flush=True, ) print("=== CDP scrape studio signals ===", flush=True) print( run( c, "python3 - <<'PY'\n" "import subprocess\n" "from pathlib import Path\n" f"script=Path('/opt/douyinWEB/backend/neko/cdp_studio_scrape.py').read_text(encoding='utf-8')\n" f"p=subprocess.run(['docker','exec','-i','{NAME}','python3','-'],input=script,capture_output=True,text=True,timeout=35)\n" "print((p.stdout or p.stderr or '')[-1500:])\n" "PY", timeout=50, ), flush=True, ) print("=== recent docker logs ===", flush=True) print(run(c, f"docker logs --tail 60 {NAME} 2>&1 | tail -60", timeout=30), flush=True) print("=== chrome stderr / neko logs if any ===", flush=True) print( run( c, f"docker exec {NAME} bash -lc '" "ls -la /var/log 2>/dev/null | head; " "ls /var/log/supervisor 2>/dev/null; " "tail -40 /var/log/supervisor/google-chrome*.log 2>/dev/null || " "tail -40 /var/log/supervisor/chromium*.log 2>/dev/null || " "tail -40 /var/log/neko/*.log 2>/dev/null || echo no_chrome_log" "'", timeout=30, ), flush=True, ) print("=== assign mapping for neko 7 ===", flush=True) print( run( c, "cd /opt/douyinWEB/backend && PYTHONPATH=/opt/douyinWEB/backend .venv/bin/python - <<'PY'\n" "from app import yt_assign_db, youtube_neko as yn\n" "for g in yt_assign_db.list_groups(include_urls=False):\n" " if int(g.get('neko_instance_id') or 0)==7:\n" " print('group', g.get('name'), g.get('id'), 'enabled', g.get('neko_enabled'), 'studio', (g.get('neko_studio_url') or '')[:100])\n" "st=yn._container_state(7, check_http=True)\n" "print('state', {k:st.get(k) for k in ('id','running','ready','status','detail','studio_url')})\n" "snap=yn.studio_on_air_lookup(7, max_age_sec=180)\n" "print('studio', {k:snap.get(k) for k in ('live_page_open','on_air','live_status','health','viewer_count','total_views','live_duration','url','detect_source')})\n" "PY", timeout=60, ), flush=True, ) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())