#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Read-only health: VPS hub binds + physical ops-neko + relay/live gate.""" from __future__ import annotations import json import sys import urllib.request import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") def ssh(host, port, user, pw, script, sudo=False, timeout=90): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120) sftp = c.open_sftp() path = f"/tmp/_health_{port}.sh" with sftp.file(path, "w") as f: f.write(script) sftp.close() cmd = f"echo '{pw}' | sudo -S -p '' bash {path}" if sudo else f"bash {path}" _i, o, e = c.exec_command(cmd, timeout=timeout) out = (o.read() + e.read()).decode("utf-8", "replace") c.close() return out def http_json(url: str, timeout: int = 12): try: req = urllib.request.Request(url, headers={"User-Agent": "dy-health/1"}) with urllib.request.urlopen(req, timeout=timeout) as r: body = r.read().decode("utf-8", "replace") code = r.status try: return code, json.loads(body) except Exception: return code, body[:500] except Exception as e: return None, str(e) VPS = r"""#!/bin/bash set +e echo '=== mem ===' free -h | head -3 echo '=== local neko containers ===' docker ps -a --format '{{.Names}} {{.Status}}' | grep -E 'douyinweb-neko' | sort echo '=== assign binds (DB) ===' python3 - <<'PY' import sqlite3 db='/opt/douyinWEB/backend/data/monitor.db' con=sqlite3.connect(db); con.row_factory=sqlite3.Row rows=con.execute(''' SELECT name, neko_instance_id, neko_enabled, neko_open_prefer, ops_neko_bind_url, ops_neko_bind_label, ops_neko_bind_edge FROM yt_assign_groups ORDER BY neko_instance_id ''').fetchall() for r in rows: d=dict(r) print(f"id={d.get('neko_instance_id')} en={d.get('neko_enabled')} prefer={d.get('neko_open_prefer')} name={d.get('name')}") print(f" bind={d.get('ops_neko_bind_url')} label={d.get('ops_neko_bind_label')} edge={d.get('ops_neko_bind_edge')}") PY echo '=== ops catalog / edge sync (if tables) ===' python3 - <<'PY' import sqlite3 con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db') for t in con.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1").fetchall(): if any(x in t[0].lower() for x in ('ops','neko','relay','studio')): print('table', t[0]) PY echo '=== api health snippets ===' curl -sS -m 8 http://127.0.0.1:8014/api/health 2>/dev/null | head -c 400; echo curl -sS -m 8 http://127.0.0.1:8014/api/youtube/assign/groups 2>/dev/null | python3 -c 'import sys,json try: d=json.load(sys.stdin); gs=d if isinstance(d,list) else d.get("groups") or d.get("items") or [] print("groups", len(gs)) for g in gs[:12]: print({k:g.get(k) for k in ("name","neko_instance_id","neko_enabled","neko_open_prefer","ops_neko_bind_url","ops_neko_open_url","relay_enabled","live") if k in g or True}) except Exception as e: print("err",e, sys.stdin.read()[:200] if False else "") ' 2>/dev/null | head -80 """ PHYS = r"""#!/bin/bash set +e echo '=== ops-neko containers ===' docker ps -a --format '{{.Names}} {{.Status}}' | grep -E 'ops-neko|neko' | sort echo '=== ops-neko chrome/TM (no changes) ===' for N in douyinweb-ops-neko-1 douyinweb-ops-neko-2; do docker inspect "$N" >/dev/null 2>&1 || continue echo "-- $N --" docker exec -i "$N" python3 - <<'PY' import os, json, urllib.request from pathlib import Path mains=0; load=False; sw=-1 for pid in os.listdir('/proc'): if not pid.isdigit(): continue try: raw=open(f'/proc/{pid}/cmdline','rb').read() except: continue if not raw: continue if b'google-chrome' in raw and b'--type=' not in raw and b'crashpad' not in raw and b'browser-launch' not in raw: mains+=1 if b'load-extension' in raw and b'dhdgff' in raw: load=True try: tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=3).read()) sw=sum(1 for t in tabs if t.get('type')=='service_worker' and 'dhdgff' in (t.get('url') or '')) urls=[(t.get('type'), (t.get('url') or '')[:100]) for t in tabs if t.get('type') in ('page','service_worker') and 'doubleclick' not in (t.get('url') or '')][:8] except Exception as e: tabs=[]; urls=[str(e)]; sw=-1 cookie=Path('/home/neko/.config/google-chrome/Default/Cookies') print('mains',mains,'load_ext',load,'tm_sw',sw,'cookies_bytes', cookie.stat().st_size if cookie.exists() else 0) for u in urls: print(' ', u) PY done echo '=== local http ops ports ===' for p in 18200 18201 9200 9201 9202 9203; do code=$(curl -sS -m 2 -o /dev/null -w '%{http_code}' http://127.0.0.1:$p/ 2>/dev/null || echo x) echo "127.0.0.1:$p $code" done echo '=== cn public ===' curl -sS -m 8 -o /dev/null -w 'cn_ops1=%{http_code}\n' https://dy.nomadro.cn/ops-neko/1/ 2>/dev/null || curl -sS -m 8 -o /dev/null -w 'cn_neko_ops_guess=%{http_code}\n' https://dy.nomadro.cn/neko/ops/1/ 2>/dev/null # discover ops open paths from api if any curl -sS -m 5 http://127.0.0.1:8014/api/ops-neko/status 2>/dev/null | head -c 800; echo """ def main(): print("########## VPS ##########") print(ssh("107.173.30.245", 22, "root", "Xiao4669805", VPS, sudo=False)) print("########## PHYSICAL ##########") print(ssh("107.173.30.245", 4014, "eric", "4669805", PHYS, sudo=True, timeout=120)) print("########## PUBLIC ##########") for url in [ "https://dylive.nomadro.com/api/health", "https://dy.nomadro.cn/api/health", "https://dylive.nomadro.com/neko/7/", "https://dy.nomadro.cn/neko/3/", ]: code, body = http_json(url) if url.endswith("health") else (None, None) if url.endswith("health"): print(url, code, str(body)[:200]) else: try: req = urllib.request.Request(url, method="GET") with urllib.request.urlopen(req, timeout=10) as r: print(url, r.status) except Exception as e: print(url, "ERR", e) if __name__ == "__main__": main()