# -*- coding: utf-8 -*- """Run on VPS: inspect focus rooms + active session consistency.""" import json import sqlite3 import time import urllib.request DB = "/opt/douyinWEB/backend/data/monitor.db" FOCUS = ["杭州光头煎饺", "阿超盖浇饭", "小易"] def main() -> None: conn = sqlite3.connect(DB) conn.row_factory = sqlite3.Row now = time.time() print("NOW", now) print("=== focus rooms ===") for name in FOCUS: print("---", name) rows = conn.execute( "SELECT id, room_id, last_status, last_anchor, active_session_id, last_checked_at FROM rooms WHERE last_anchor LIKE ? OR note LIKE ?", (f"%{name}%", f"%{name}%"), ).fetchall() for r in rows: print(dict(r)) sess = conn.execute( """ SELECT id, room_id, anchor_name, status, started_at, ended_at, end_reason, duration_seconds FROM sessions WHERE anchor_name LIKE ? ORDER BY started_at DESC LIMIT 3 """, (f"%{name}%",), ).fetchall() for s in sess: d = dict(s) if d.get("started_at"): d["age_h"] = round((now - float(d["started_at"])) / 3600, 2) print("sess", d) print("=== active vs room status ===") for s in conn.execute( "SELECT id, room_id, room_pk, anchor_name, started_at FROM sessions WHERE status='active' AND ended_at IS NULL" ).fetchall(): room = conn.execute( "SELECT last_status, active_session_id FROM rooms WHERE id=?", (s["room_pk"],), ).fetchone() el = now - float(s["started_at"]) print( { "anchor": s["anchor_name"], "room_id": s["room_id"], "elapsed_h": round(el / 3600, 2), "room_status": room["last_status"] if room else None, "sid_match": ((room["active_session_id"] if room else None) == s["id"]), } ) for path in ("/api/monitor", "/api/health", "/api/sessions/active"): try: raw = urllib.request.urlopen(f"http://127.0.0.1:8014{path}", timeout=20).read().decode() print(path, raw[:400]) except Exception as exc: print(path, "ERR", exc) if __name__ == "__main__": main()