#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Read-only: physical host memory + neko3 crash clues.""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") SCRIPT = r""" set -e echo '=== MEM free -h ===' free -h echo '=== MEMINFO ===' grep -E 'MemTotal|MemAvailable|SwapTotal|SwapFree|Committed_AS|CommitLimit' /proc/meminfo echo '=== API host metrics ===' curl -sS -m 8 http://127.0.0.1:8014/api/host/metrics 2>/dev/null | head -c 500; echo echo '=== NEKO containers ===' docker ps -a --filter name=neko --format 'table {{.Names}}\t{{.Status}}\t{{.RunningFor}}' 2>/dev/null | head -40 echo '=== docker stats ===' docker stats --no-stream --format 'table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.CPUPerc}}' 2>/dev/null | head -40 echo '=== neko3 inspect ===' docker inspect douyinweb-neko-3 --format 'Status={{.State.Status}} OOM={{.State.OOMKilled}} Exit={{.State.ExitCode}} Restart={{.RestartCount}} Started={{.State.StartedAt}} Finished={{.State.FinishedAt}} Error={{.State.Error}}' 2>/dev/null || echo 'no douyinweb-neko-3' docker inspect neko-3 --format 'Status={{.State.Status}} OOM={{.State.OOMKilled}} Exit={{.State.ExitCode}} Restart={{.RestartCount}}' 2>/dev/null || true echo '=== OOM dmesg/journal ===' dmesg -T 2>/dev/null | grep -iE 'oom|Out of memory|Killed process|chrome' | tail -40 || true journalctl -k --since '3 days ago' 2>/dev/null | grep -iE 'oom|Killed process' | tail -30 || true echo '=== chrome inside neko3 ===' CID=$(docker ps -q --filter name=douyinweb-neko-3 | head -1) if [ -z "$CID" ]; then CID=$(docker ps -aq --filter name=neko-3 | head -1); fi echo CID=$CID if [ -n "$CID" ]; then docker exec "$CID" bash -lc 'ps aux --sort=-%mem | head -25' 2>/dev/null || true docker logs --tail 80 "$CID" 2>&1 | tail -80 || true fi echo '=== PVE balloon hint (guest sees) ===' cat /sys/devices/system/memory/*/online 2>/dev/null | wc -l || true lscpu | grep -E 'CPU\(s\)|Model name' || true """ def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False) cmd = "echo '4669805' | sudo -S -p '' bash -s" _, o, e = c.exec_command(cmd, timeout=120) o.channel.sendall(SCRIPT.encode()) o.channel.shutdown_write() out = (o.read() + e.read()).decode("utf-8", "replace") print(out[-16000:] if len(out) > 16000 else out) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())