94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Diagnose CPU 100% on dy.nomadro.live vs dylive — read-only."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOSTS = [
|
|
("dy-live", "108.174.50.68"),
|
|
("dylive", "107.173.30.245"),
|
|
]
|
|
PASS = "Xiao4669805"
|
|
|
|
SCRIPT = r"""
|
|
set +e
|
|
echo '=== host ==='
|
|
hostname; nproc; free -h | head -2
|
|
uptime
|
|
echo
|
|
echo '=== top cpu (snapshot) ==='
|
|
ps aux --sort=-%cpu | head -25
|
|
echo
|
|
echo '=== load / steal ==='
|
|
mpstat 1 3 2>/dev/null || vmstat 1 3
|
|
echo
|
|
echo '=== docker / neko ==='
|
|
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.RunningFor}}' 2>/dev/null | head -40
|
|
echo neko_count=$(docker ps -q --filter name=neko 2>/dev/null | wc -l)
|
|
echo
|
|
echo '=== chrome / ffmpeg counts ==='
|
|
echo chrome=$(pgrep -c chrome 2>/dev/null || pgrep -c chromium 2>/dev/null || echo 0)
|
|
echo ffmpeg=$(pgrep -c ffmpeg 2>/dev/null || echo 0)
|
|
echo node=$(pgrep -c node 2>/dev/null || echo 0)
|
|
echo python=$(pgrep -c python 2>/dev/null || echo 0)
|
|
echo npm=$(pgrep -af 'npm|next|node.*build' 2>/dev/null | grep -v grep | head -15)
|
|
echo
|
|
echo '=== systemd hot ==='
|
|
systemctl is-active douyinweb-api douyinweb-web douyinweb-s3 douyinweb-pb douyinweb-yt 2>/dev/null
|
|
systemctl status douyinweb-api --no-pager -l 2>&1 | head -20
|
|
echo
|
|
echo '=== api threads / cpu ==='
|
|
PID=$(ss -lntp 2>/dev/null | awk '/:8014/ {match($0,/pid=[0-9]+/); if(RSTART){print substr($0,RSTART+4,RLENGTH-4); exit}}')
|
|
echo api_pid=$PID
|
|
if [ -n "$PID" ]; then
|
|
ps -p $PID -o pid,pcpu,pmem,rss,nlwp,etime,cmd
|
|
# children
|
|
ps --ppid $PID -o pid,pcpu,pmem,rss,cmd --sort=-pcpu 2>/dev/null | head -15
|
|
fi
|
|
echo
|
|
echo '=== assign neko enabled ==='
|
|
cd /opt/douyinWEB/backend 2>/dev/null && ./.venv/bin/python - <<'PY'
|
|
from app.db import _connect, _lock
|
|
with _lock:
|
|
conn=_connect()
|
|
rows=conn.execute('SELECT name, neko_instance_id, neko_enabled FROM yt_assign_groups ORDER BY neko_instance_id').fetchall()
|
|
en=0
|
|
for r in rows:
|
|
print(dict(r) if hasattr(r,'keys') else r)
|
|
if r[2]: en+=1
|
|
print('enabled_count', en, 'total', len(rows))
|
|
PY
|
|
echo
|
|
echo '=== recent api log cpu-ish ==='
|
|
journalctl -u douyinweb-api -n 40 --no-pager 2>/dev/null | tail -40
|
|
echo HOST_DONE
|
|
"""
|
|
|
|
|
|
def connect(host):
|
|
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=120)
|
|
return c
|
|
except Exception as e:
|
|
print(f"retry {host} {i}: {e}", flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit(f"ssh fail {host}")
|
|
|
|
|
|
for label, host in HOSTS:
|
|
print(f"\n######## {label} {host} ########", flush=True)
|
|
c = connect(host)
|
|
_i, o, e = c.exec_command(SCRIPT, timeout=90)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
print("ALL_DONE", flush=True)
|