84 lines
3.9 KiB
Python
84 lines
3.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''
|
|
import sqlite3, datetime, json
|
|
from collections import Counter
|
|
BJ=datetime.timezone(datetime.timedelta(hours=8))
|
|
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
con.row_factory=sqlite3.Row
|
|
gid='45f9bd79-2039-4985-8176-5e41b014281b'
|
|
g=con.execute('SELECT id,name,neko_instance_id,ops_neko_slot,neko_open_prefer,ops_neko_open_url,neko_enabled FROM yt_assign_groups WHERE id=?',(gid,)).fetchone()
|
|
print('group', dict(g) if g else None)
|
|
rows=con.execute('SELECT * FROM yt_relay_sessions WHERE group_id=? ORDER BY started_at DESC LIMIT 100',(gid,)).fetchall()
|
|
print('n_sessions', len(rows))
|
|
print('reasons', dict(Counter(str(r['end_reason'] or '') for r in rows)))
|
|
print('=== first 40 by time desc ===')
|
|
for r in rows[:40]:
|
|
d=dict(r)
|
|
for k in ('started_at','ended_at'):
|
|
try: d[k+'_bj']=datetime.datetime.fromtimestamp(float(d[k]),BJ).strftime('%m-%d %H:%M:%S')
|
|
except Exception: pass
|
|
meta=d.get('metadata_json') or ''
|
|
print(d.get('started_at_bj'), '->', d.get('ended_at_bj'), 'dur', d.get('duration_seconds'), 'reason', d.get('end_reason'), 'status', d.get('status'), 'room', d.get('source_room_id'), 'meta', str(meta)[:120])
|
|
# cluster 04:00-06:00 BJ on 09-10
|
|
print('=== 09-10 04:00-06:30 cluster ===')
|
|
cluster=[]
|
|
for r in rows:
|
|
try:
|
|
st=float(r['started_at'])
|
|
bj=datetime.datetime.fromtimestamp(st,BJ)
|
|
except Exception:
|
|
continue
|
|
if bj.month==9 and bj.day==10 and 4<=bj.hour<7:
|
|
cluster.append(r)
|
|
print('cluster_n', len(cluster))
|
|
print('cluster_reasons', dict(Counter(str(r['end_reason'] or '') for r in cluster)))
|
|
durs=[float(r['duration_seconds'] or 0) for r in cluster]
|
|
if durs:
|
|
print('dur_min/avg/max', min(durs), sum(durs)/len(durs), max(durs))
|
|
# studio samples for this group overnight
|
|
print('=== studio samples gid overnight ===')
|
|
samples=con.execute('SELECT * FROM yt_studio_samples WHERE group_id=? ORDER BY ts DESC LIMIT 80',(gid,)).fetchall()
|
|
print('n', len(samples))
|
|
for s in samples[:25]:
|
|
d=dict(s)
|
|
try: d['ts_bj']=datetime.datetime.fromtimestamp(float(d['ts']),BJ).strftime('%m-%d %H:%M:%S')
|
|
except Exception: pass
|
|
print(d.get('ts_bj'), 'on_air', d.get('on_air'), 'status', d.get('live_status'), 'health', d.get('health'), 'page', d.get('live_page_open'), 'ref', d.get('neko_ref'), 'src', d.get('detect_source'))
|
|
# also count on_air=1 for this group today
|
|
n_live=con.execute('SELECT COUNT(*) FROM yt_studio_samples WHERE group_id=? AND on_air=1',(gid,)).fetchone()[0]
|
|
n_wait=con.execute('SELECT COUNT(*) FROM yt_studio_samples WHERE group_id=? AND on_air=0',(gid,)).fetchone()[0]
|
|
print('samples on_air1', n_live, 'on_air0', n_wait)
|
|
# successful long sessions earlier same push_date
|
|
print('=== longer sessions same day ===')
|
|
for r in rows:
|
|
if float(r['duration_seconds'] or 0) >= 300:
|
|
try:
|
|
sb=datetime.datetime.fromtimestamp(float(r['started_at']),BJ).strftime('%m-%d %H:%M:%S')
|
|
except Exception:
|
|
sb='?'
|
|
print(sb, 'dur', r['duration_seconds'], 'reason', r['end_reason'], 'date', r['push_date'])
|
|
st=con.execute('SELECT status,error,ffmpeg_pid,updated_at FROM yt_relay_states WHERE group_id=?',(gid,)).fetchone()
|
|
print('state', dict(st) if st else None)
|
|
# how many sessions on push_date before flap
|
|
print('=== by push_date ===')
|
|
for row in con.execute('SELECT push_date, COUNT(*), AVG(duration_seconds), SUM(CASE WHEN end_reason=\"studio_not_on_air\" THEN 1 ELSE 0 END) FROM yt_relay_sessions WHERE group_id=? GROUP BY push_date ORDER BY push_date DESC LIMIT 8',(gid,)):
|
|
print(tuple(row))
|
|
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[:2000])
|
|
c.close()
|