122 lines
4.9 KiB
Python
122 lines
4.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Broad read-only health sweep: dy + dylive (live/neko/shorts/yt-long/disk/quota)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
PASS = "Xiao4669805"
|
|
HOSTS = [("dy", "108.174.50.68"), ("dylive", "107.173.30.245")]
|
|
|
|
REMOTE = r'''
|
|
set +e
|
|
echo "=== host $(hostname) $(date -Is) ==="
|
|
echo "-- mem --"
|
|
free -h | head -3
|
|
echo "-- disk --"
|
|
df -h / /opt /var/lib/docker 2>/dev/null | head -10
|
|
echo "-- units --"
|
|
for u in douyinweb-api douyinweb-web douyinweb-yt douyinweb-pb; do
|
|
printf '%s ' "$u"; systemctl is-active "$u" 2>/dev/null; done
|
|
echo
|
|
echo "-- neko containers --"
|
|
docker ps -a --format '{{.Names}}\t{{.Status}}' 2>/dev/null | grep -i neko | sort
|
|
echo "-- oom/kill recent (journal 6h) --"
|
|
journalctl --since '6 hours ago' --no-pager 2>/dev/null | grep -iE 'Out of memory|oom-kill|Killed process|SIGILL|neko.*(exit|restart)|douyinweb-neko' | tail -25
|
|
echo "-- api relay/shorts/ytlong via python --"
|
|
cd /opt/douyinWEB/backend && .venv/bin/python <<'PY'
|
|
import json, time
|
|
from app import db
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline
|
|
from app import yt_long_db
|
|
from app.shorts_yt_quota import quota_budgets_by_profile
|
|
from app.timeutil import push_date_from_ts
|
|
try:
|
|
from app import youtube_neko
|
|
except Exception as e:
|
|
youtube_neko = None
|
|
print("neko_import_err", e)
|
|
|
|
cfg = db.get_settings_map()
|
|
day = push_date_from_ts(time.time())
|
|
print("day", day)
|
|
print("relay_enabled", cfg.get("youtube_relay_enabled"), "exclusive", cfg.get("youtube_relay_exclusive_live"))
|
|
print("shorts_pipeline", cfg.get("shorts_enabled"), cfg.get("shorts_pipeline_enabled"))
|
|
print("yt_long", cfg.get("yt_long_enabled"), "disk_min", cfg.get("clips_min_free_gb"))
|
|
print("limited_day", cfg.get("yt_long_quota_limited_day"), str(cfg.get("yt_long_quota_limited_reason") or "")[:120])
|
|
st = youtube_relay_pipeline.status()
|
|
print("relay_running", st.get("running"), "pushing", st.get("pushing_count"), "winner", st.get("exclusive_winner_group_id"))
|
|
# neko mismatch: running vs enabled
|
|
try:
|
|
from app import yt_assign_db
|
|
groups = yt_assign_db.list_groups(include_urls=False)
|
|
print("assign_groups", len(groups))
|
|
mismatch = []
|
|
for g in groups:
|
|
nid = int(g.get("neko_instance_id") or 0)
|
|
if nid < 1:
|
|
continue
|
|
en = bool(g.get("neko_enabled"))
|
|
state = youtube_neko._container_state(nid, check_http=False) if youtube_neko else {}
|
|
run = bool(state.get("running"))
|
|
if en != run:
|
|
mismatch.append((g.get("name"), nid, "enabled", en, "running", run, state.get("status")))
|
|
print("neko_enabled_vs_running_mismatch", len(mismatch))
|
|
for row in mismatch[:12]:
|
|
print(" ", row)
|
|
except Exception as e:
|
|
print("neko_mismatch_err", e)
|
|
print("yt_quota_budgets", json.dumps(quota_budgets_by_profile(cfg), ensure_ascii=False)[:900])
|
|
print("yt_long_upload_used", yt_long_db.yt_long_upload_used(day), "daily_max", yt_long_db.yt_long_daily_max(cfg))
|
|
try:
|
|
s = db.shorts_channels_quota_summary(day)
|
|
print("shorts_uploaded_sum", sum(int(r.get("uploaded") or 0) for r in s), "channels", len(s), "gap", sum(int(r.get("gap") or 0) for r in s))
|
|
except Exception as e:
|
|
print("shorts_err", e)
|
|
# stuck jobs sample
|
|
try:
|
|
for stname in ("uploading", "recording", "pending"):
|
|
d = db.list_shorts_jobs(push_date=day, status=stname, limit=5, offset=0)
|
|
print(f"shorts_{stname}", d.get("total"), "sample", [ (j.get("id"), j.get("channel_name") or j.get("anchor_name"), j.get("error")) for j in (d.get("jobs") or [])[:3]])
|
|
except Exception as e:
|
|
print("jobs_err", e)
|
|
try:
|
|
for stname in ("uploading", "recording", "scheduled", "pending"):
|
|
d = yt_long_db.list_yt_long_jobs_page(status=stname, push_date=day, limit=5, offset=0)
|
|
print(f"ytlong_{stname}", d.get("total"))
|
|
except Exception as e:
|
|
print("ytlong_jobs_err", e)
|
|
PY
|
|
echo "-- ffmpeg count --"
|
|
ps -eo pid,etime,cmd | grep -E '[f]fmpeg' | wc -l
|
|
echo "-- last api errors 2h --"
|
|
journalctl -u douyinweb-api --since '2 hours ago' --no-pager 2>/dev/null | grep -iE 'ERROR|Traceback|QUOTA|OOM|timeout|neko wait blocked|studio_not_on_air' | tail -30
|
|
'''
|
|
|
|
|
|
def run_host(label: str, host: str) -> None:
|
|
print(f"\n########## {label} {host} ##########", flush=True)
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(host, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=90)
|
|
break
|
|
except Exception as e:
|
|
print(f"ssh_retry {i}: {e}", flush=True)
|
|
time.sleep(2 + i)
|
|
else:
|
|
print("ssh_fail", flush=True)
|
|
return
|
|
_, o, e = c.exec_command(REMOTE, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
|
|
for label, host in HOSTS:
|
|
run_host(label, host)
|