douyinWEB/scripts/_full_audit_now.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

79 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""Full online health / yt-long / shorts snapshot."""
import json
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
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)
def run(cmd, timeout=120):
_, o, e = c.exec_command(cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace").strip()
print(out[-12000:] if len(out) > 12000 else out, flush=True)
return out
print("=== SVC ===")
print(run("systemctl is-active douyinweb-api douyinweb-web douyinweb-pb; df -h / | tail -1; free -m | head -2"))
print("=== GIT ===")
print(run("cd /opt/douyinWEB && git log --oneline -5 && git status -sb"))
print("=== HEALTH KEYS ===")
print(run(r"""python3 - <<'PY'
import json,urllib.request
h=json.load(urllib.request.urlopen('http://127.0.0.1:8014/api/health', timeout=20))
print('ok', h.get('ok'))
for k in ['monitor','shorts','yt_long','tiktok','x_clips','youtube_monitor']:
v=h.get(k)
if isinstance(v, dict):
keys=['enabled','running','busy','quota_gap','quota_used','daily_max','last_error','processed','sampled','live_count','douyin_live_count']
print(k, {kk:v.get(kk) for kk in keys if kk in v or True})
else:
print(k, v)
mon=h.get('monitor') or {}
print('monitor_live', mon.get('live_count'), 'rooms', mon.get('room_count'), 'overdue', (mon.get('overdue') or {}).get('count'))
sh=h.get('shorts') or {}
print('shorts_enabled', sh.get('enabled'), 'gap', sh.get('quota_gap'), 'err', (sh.get('last_error') or '')[:80])
PY"""))
print("=== YT LONG DB ===")
print(run(r"""cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python - <<'PY'
from app import db, yt_long_db
from app.yt_long_pipeline import yt_long_pipeline
from collections import Counter
import time
db.init_db()
cfg=db.get_settings_map()
print('enabled', cfg.get('yt_long_enabled'), 'daily_max', cfg.get('yt_long_daily_max'), 'ch_max', cfg.get('yt_long_channel_daily_max'), 'conc', cfg.get('yt_long_max_concurrent'), 'live_sample', cfg.get('yt_long_live_sample'), 'dedupe', cfg.get('yt_long_dedupe_room_day'))
st=yt_long_pipeline.status()
print('pipe', {k:st.get(k) for k in ['enabled','running','busy','quota_used','quota_gap','daily_max','sampled','processed','last_error','douyin_live_count']})
jobs=yt_long_db.list_yt_long_jobs(limit=50)
print('jobs', dict(Counter(j.get('status') for j in jobs)), 'n', len(jobs))
for j in jobs[:15]:
age=time.time()-float(j.get('updated_at') or 0)
print(j.get('status'), round(age),'s', (j.get('anchor_name') or '')[:18], 'err=',(j.get('error') or '')[:50], 'yt=', bool(j.get('youtube_url')))
chs=yt_long_db.list_yt_long_channels()
print('channels', len(chs), 'enabled', sum(1 for c in chs if c.get('enabled')), 'auth', sum(1 for c in chs if str(c.get('refresh_token') or '').strip()))
from app.yt_long_seo import YT_LONG_TITLES, YT_LONG_DESCS
print('seo', len(YT_LONG_TITLES), len(YT_LONG_DESCS))
PY"""))
print("=== SHORTS TODAY ===")
print(run(r"""cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python - <<'PY'
from app import db
from app.timeutil import push_date_from_ts
from collections import Counter
import time
db.init_db()
day=push_date_from_ts(time.time())
jb=db.list_shorts_jobs(push_date=day, limit=50)
jobs=jb.get('jobs') or []
print('day', day, 'total', jb.get('total'), dict(Counter(j.get('status') for j in jobs)))
cfg=db.get_settings_map()
print('shorts_enabled', cfg.get('shorts_enabled'), 'live_sample', cfg.get('shorts_live_sample'))
PY"""))
print("=== FFMPEG / DISK CLIPS ===")
print(run("ps aux | grep -E '[f]fmpeg' | wc -l; du -sh /opt/douyinWEB/backend/data/clips /opt/douyinWEB/backend/data/clips/yt_long 2>/dev/null; ls /opt/douyinWEB/backend/data/clips/yt_long 2>/dev/null | wc -l"))
print("=== API LOG ERR ===")
print(run("journalctl -u douyinweb-api --since '30 min ago' --no-pager | grep -iE 'error|traceback|yt_long|CRITICAL' | tail -40"))
c.close()