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

111 lines
4.2 KiB
Python

#!/usr/bin/env python3
"""Deeper yt-long diagnosis on dylive."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "107.173.30.245"
PASS = "Xiao4669805"
def run(c, cmd, timeout=60):
print(f"\n===== {cmd[:90]} =====", flush=True)
_i, o, e = c.exec_command(cmd, timeout=timeout)
print(o.read().decode("utf-8", "replace")[:15000], flush=True)
err = e.read().decode("utf-8", "replace")
if err.strip():
print("[stderr]", err[:800], flush=True)
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(HOST, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
break
except Exception as ex:
print(ex, flush=True)
time.sleep(1 + i)
else:
raise SystemExit("fail")
run(c, "df -h / /opt /opt/douyinWEB /opt/douyinWEB/backend/data 2>/dev/null; df -h | head -20")
run(
c,
r"""
python3 - <<'PY'
import sqlite3, time, json
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
cur=con.cursor()
# kv settings
print('---kv yt_long---')
for k,v in cur.execute("SELECT key,value FROM kv_settings WHERE key LIKE '%yt_long%' OR key LIKE '%disk%' ORDER BY key"):
print(k, '=', (v[:200]+'...') if len(str(v))>200 else v)
day='2026-09-13'
print('---status counts today---')
for r in cur.execute("SELECT status, COUNT(*) c FROM yt_long_jobs WHERE push_date=? GROUP BY status ORDER BY c DESC", (day,)):
print(dict(status=r[0], c=r[1]))
print('---errors today top---')
for r in cur.execute("SELECT COALESCE(error,''), COUNT(*) c FROM yt_long_jobs WHERE push_date=? GROUP BY 1 ORDER BY c DESC LIMIT 15", (day,)):
print(r[0][:120] or '(empty)', r[1])
print('---uploaded today---')
print(cur.execute("SELECT COUNT(*) FROM yt_long_jobs WHERE push_date=? AND status='uploaded'", (day,)).fetchone()[0])
print('---scheduled with clip---')
print(cur.execute("SELECT COUNT(*) FROM yt_long_jobs WHERE push_date=? AND status='scheduled' AND clip_path!=''", (day,)).fetchone()[0])
print('---pending---', cur.execute("SELECT COUNT(*) FROM yt_long_jobs WHERE push_date=? AND status='pending'", (day,)).fetchone()[0])
print('---recording/uploading---')
for st in ('recording','uploading','clipping','encoding'):
n=cur.execute("SELECT COUNT(*) FROM yt_long_jobs WHERE push_date=? AND status=?", (day,st)).fetchone()[0]
if n: print(st, n)
print('---channels enabled---')
cols=[x[1] for x in cur.execute('PRAGMA table_info(yt_long_channels)')]
print('cols', cols)
# guess enabled column
q="SELECT COUNT(*) FROM yt_long_channels"
print('channels_total', cur.execute(q).fetchone()[0])
if 'enabled' in cols:
print('enabled', cur.execute("SELECT COUNT(*) FROM yt_long_channels WHERE enabled=1").fetchone()[0])
# recent uploaded ever
print('---last uploaded jobs---')
for r in cur.execute("SELECT id,status,error,push_date,upload_at,youtube_video_id,substr(title,1,40) FROM yt_long_jobs WHERE status='uploaded' ORDER BY upload_at DESC LIMIT 5"):
print(r)
print('---disk_low jobs---')
print(cur.execute("SELECT COUNT(*) FROM yt_long_jobs WHERE error LIKE 'disk_low%'").fetchone()[0])
for r in cur.execute("SELECT id,status,error,attempts,updated_at FROM yt_long_jobs WHERE error LIKE 'disk_low%' ORDER BY updated_at DESC LIMIT 5"):
print(r)
PY
""",
)
run(
c,
r"""
# call status via python inside app context if possible
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app import db
from app.yt_long_pipeline import yt_long_pipeline
from app import yt_long_db
cfg=db.get_settings_map()
keys=[k for k in sorted(cfg) if 'yt_long' in k]
for k in keys:
print(f'{k}={cfg.get(k)!r}')
print('---status---')
st=yt_long_pipeline.status_light() if hasattr(yt_long_pipeline,'status_light') else yt_long_pipeline.status()
import json
print(json.dumps(st, ensure_ascii=False, indent=2)[:3000])
print('pipeline_task', getattr(yt_long_pipeline,'_task',None))
PY
""",
)
run(c, "du -sh /opt/douyinWEB/backend/data/clips/* 2>/dev/null | sort -h | tail -20; ls -la /opt/douyinWEB/backend/data/clips/ 2>/dev/null")
c.close()
if __name__ == "__main__":
main()