Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Check the three suspicious rooms and whether active timers match Douyin."""
|
|
import json
|
|
import time
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
|
|
FOCUS = ["杭州光头煎饺", "阿超盖浇饭", "小易"]
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
script = r'''
|
|
import json, sqlite3, time, urllib.request
|
|
from pathlib import Path
|
|
db = "/opt/douyinWEB/backend/data/monitor.db"
|
|
conn = sqlite3.connect(db)
|
|
conn.row_factory = sqlite3.Row
|
|
now = time.time()
|
|
focus = ["杭州光头煎饺", "阿超盖浇饭", "小易"]
|
|
print("NOW", now)
|
|
print("=== focus rooms ===")
|
|
for name in focus:
|
|
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["elapsed_if_active"] = now - float(d["started_at"])
|
|
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, last_anchor 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,
|
|
"room_active_sid": (room["active_session_id"] if room else None) == s["id"],
|
|
})
|
|
|
|
# probe first 5 active via live check endpoint if exists
|
|
print("=== api monitor ===")
|
|
try:
|
|
print(urllib.request.urlopen("http://127.0.0.1:8014/api/monitor", timeout=20).read().decode()[:500])
|
|
except Exception as e:
|
|
print("monitor err", e)
|
|
try:
|
|
print(urllib.request.urlopen("http://127.0.0.1:8014/api/health", timeout=10).read().decode()[:300])
|
|
except Exception as e:
|
|
print("health err", e)
|
|
'''
|
|
|
|
cmd = f"cd /opt/douyinWEB && /opt/douyinWEB/backend/.venv/bin/python - <<'PY'\n{script}\nPY"
|
|
_, o, e = c.exec_command(cmd, timeout=60)
|
|
print(o.read().decode("utf-8", errors="replace"))
|
|
err = e.read().decode("utf-8", errors="replace")
|
|
if err.strip():
|
|
print("ERR", err[-800:])
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|