69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import datetime
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
BJ = datetime.timezone(datetime.timedelta(hours=8))
|
|
|
|
REMOTE = r'''
|
|
import sqlite3, datetime
|
|
BJ=datetime.timezone(datetime.timedelta(hours=8))
|
|
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
con.row_factory=sqlite3.Row
|
|
g=con.execute("SELECT id,name,neko_instance_id,neko_enabled FROM yt_assign_groups WHERE lower(name) LIKE '%nomad%'").fetchall()
|
|
print('groups', [dict(x) for x in g])
|
|
gid=str(g[0]['id']) if g else ''
|
|
print('gid', gid)
|
|
cols=[x[1] for x in con.execute('PRAGMA table_info(yt_relay_sessions)')]
|
|
print('sess_cols', cols)
|
|
rows=con.execute('SELECT * FROM yt_relay_sessions WHERE group_id=? ORDER BY started_at DESC LIMIT 60',(gid,)).fetchall()
|
|
print('=== sessions ===')
|
|
for r in rows:
|
|
d=dict(r)
|
|
for k in list(d):
|
|
if 'at' in k or k in ('started_at','ended_at','created_at'):
|
|
try:
|
|
d[k+'_bj']=datetime.datetime.fromtimestamp(float(d[k]),BJ).strftime('%m-%d %H:%M:%S')
|
|
except Exception:
|
|
pass
|
|
keys=['id','started_at_bj','ended_at_bj','end_reason','status','source_room_id','error']
|
|
print({k:d.get(k) for k in keys if k in d or d.get(k) is not None})
|
|
# earliest studio_not_on_air cluster
|
|
print('=== count by end_reason last 80 ===')
|
|
from collections import Counter
|
|
c=Counter(str(dict(r).get('end_reason') or '') for r in rows)
|
|
print(dict(c))
|
|
# relay state + last error
|
|
st=con.execute('SELECT * FROM yt_relay_states WHERE group_id=?',(gid,)).fetchone()
|
|
if st:
|
|
d=dict(st)
|
|
print('state', {k:d.get(k) for k in ('status','error','ffmpeg_pid','source_room_id','updated_at')})
|
|
print('recent_log', (d.get('recent_log') or '')[:800])
|
|
# studio samples
|
|
try:
|
|
sc=[x[1] for x in con.execute('PRAGMA table_info(yt_studio_samples)')]
|
|
print('sample_cols', sc)
|
|
# ops-2 often nomadvlog
|
|
samples=con.execute('SELECT * FROM yt_studio_samples ORDER BY ts DESC LIMIT 40').fetchall()
|
|
for s in samples:
|
|
d=dict(s)
|
|
try: d['ts_bj']=datetime.datetime.fromtimestamp(float(d['ts']),BJ).strftime('%m-%d %H:%M:%S')
|
|
except Exception: pass
|
|
print({k:d.get(k) for k in ('ts_bj','neko_ref','neko_kind','on_air','live_status','live_page_open','health','group_id')})
|
|
except Exception as e:
|
|
print('no samples', e)
|
|
con.close()
|
|
'''
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
_, o, e = c.exec_command("python3 - <<'PY'\n" + REMOTE + "\nPY", timeout=60)
|
|
print(o.read().decode("utf-8", "replace"))
|
|
err = e.read().decode("utf-8", "replace")
|
|
if err:
|
|
print("STDERR", err)
|
|
c.close()
|