douyinWEB/scripts/_dump_studio_telemetry.py
2026-09-13 22:10:49 -05:00

89 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
"""Dump studio telemetry + yt_studio DB for assign groups."""
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r'''
import json, sqlite3, glob, os, time
os.chdir("/opt/douyinWEB/backend")
con=sqlite3.connect("data/monitor.db")
con.row_factory=sqlite3.Row
print("=== assign groups ===")
for r in con.execute("select id,name,youtube_channel_id,channel_pk,ops_neko_slot,neko_open_prefer from yt_assign_groups where enabled=1"):
d=dict(r)
print(d["name"], d["id"][:8], "cid", (d.get("youtube_channel_id") or "")[:14], "slot", d.get("ops_neko_slot"), "prefer", d.get("neko_open_prefer"))
print("=== tables with studio ===")
tabs=[r[0] for r in con.execute("select name from sqlite_master where type='table'")]
print([t for t in tabs if "studio" in t.lower() or "neko" in t.lower() or "tele" in t.lower()])
for t in tabs:
if "studio" in t.lower():
cols=[r[1] for r in con.execute(f"pragma table_info({t})")]
print("table", t, cols)
try:
rows=list(con.execute(f"select * from {t} order by rowid desc limit 15"))
for r in rows:
print(" ", dict(r))
except Exception as e:
print(" err", e)
print("=== telemetry files ===")
for p in sorted(glob.glob("data/neko/**/*.json", recursive=True))[:40]:
try:
obj=json.load(open(p,encoding="utf-8"))
except Exception:
continue
# summarize
if isinstance(obj, dict):
pl=obj.get("payload") or obj
ls=pl.get("live_status") or obj.get("live_status")
url=pl.get("url") or obj.get("url") or ""
ref=obj.get("neko_ref") or pl.get("neko_ref") or ""
on=pl.get("on_air") or pl.get("encoder_receiving")
age=None
ra=obj.get("received_at") or pl.get("received_at")
if isinstance(ra,(int,float)):
# handle weird future timestamps
age=ra
if ls or "studio" in p:
print(p, "ref", ref, "status", ls, "on_air/enc", on, "url", (url or "")[:70], "recv", ra)
print("=== minute jsonl tails ===")
for p in sorted(glob.glob("data/neko/studio_minute/*.jsonl")):
try:
lines=open(p,encoding="utf-8").read().strip().splitlines()[-3:]
print(p, "n", len(open(p,encoding="utf-8").read().strip().splitlines()))
for ln in lines:
o=json.loads(ln)
pl=o.get("payload") or o
print(" ", pl.get("live_status"), pl.get("on_air"), (pl.get("url") or "")[:60], pl.get("stream_title","")[:40])
except Exception as e:
print(p, e)
'''
def run(port, user, pwd, label):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", port=port, username=user, password=pwd, timeout=25)
stdin, stdout, stderr = c.exec_command("python3 -", timeout=60)
stdin.write(REMOTE)
stdin.channel.shutdown_write()
print("########", label, "########")
print(stdout.read().decode("utf-8", "replace"))
err = stderr.read().decode("utf-8", "replace")
if err.strip():
print("STDERR", err[-800:])
c.close()
if __name__ == "__main__":
run(22, "root", "Xiao4669805", "vps")
run(4014, "eric", "4669805", "phys")