douyinWEB/scripts/_inventory_dylive_vs_physical_db.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

59 lines
1.9 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Inventory rooms/core tables on dylive VPS vs physical guest."""
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def ssh(h, p, u, pw):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(h, p, u, pw, timeout=45, banner_timeout=90, allow_agent=False, look_for_keys=False)
return c
def run(c, cmd, t=60):
_, o, e = c.exec_command(cmd, timeout=t)
return (o.read() + e.read()).decode("utf-8", "replace")
SQL = r'''
python3 - <<'PY'
import sqlite3
from pathlib import Path
p = Path("/opt/douyinWEB/backend/data/monitor.db")
print("db", p, "exists", p.is_file(), "size", p.stat().st_size if p.is_file() else 0)
if not p.is_file():
raise SystemExit(0)
c = sqlite3.connect(str(p))
c.row_factory = sqlite3.Row
tables = [r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1")]
print("tables", tables)
for t in tables:
try:
n = c.execute(f"SELECT COUNT(*) FROM [{t}]").fetchone()[0]
except Exception as ex:
n = f"err:{ex}"
print(f" {t}: {n}")
if "rooms" in tables:
print("--- rooms sample ---")
for r in c.execute("SELECT id, room_id, url, nickname, enabled, last_status FROM rooms ORDER BY id LIMIT 8"):
print(dict(r))
print("enabled", c.execute("SELECT COUNT(*) FROM rooms WHERE enabled=1").fetchone()[0])
c.close()
PY
'''
print("===== DYLIVE VPS (local app) =====")
v = ssh("107.173.30.245", 22, "root", "Xiao4669805")
print(run(v, SQL, 30))
print("path check", run(v, "ls -la /opt/douyinWEB/backend/data/monitor.db* 2>/dev/null; curl -sS -m 5 https://dylive.nomadro.com/api/health | head -c 300; echo", 20))
v.close()
print("===== PHYSICAL =====")
g = ssh("107.173.30.245", 4014, "eric", "4669805")
print(run(g, f"echo 4669805 | sudo -S -p '' bash -c '{SQL}'", 40))
g.close()