douyinWEB/scripts/_check_guest_balloon_mem.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

65 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
"""Show guest-visible RAM vs balloon; neko count."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
REMOTE = r'''
import subprocess
def sh(c):
return subprocess.check_output(c, shell=True, text=True, errors="replace")
print("=== free ===")
print(sh("free -h"))
print("=== meminfo ===")
print(sh("grep -E 'MemTotal|MemAvailable|MemFree|SwapTotal|SwapFree|Committed' /proc/meminfo"))
print("=== balloon? ===")
print(sh("ls /sys/devices/virtual/virtio*/*/balloon 2>/dev/null; ls /sys/bus/virtio/drivers/virtio_balloon 2>/dev/null; dmesg 2>/dev/null | grep -i balloon | tail -5 || true"))
print("=== neko running ===")
print(sh("docker ps --format '{{.Names}} {{.Status}}' | grep neko | sort || true"))
print("=== load ===")
print(sh("uptime; nproc"))
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=40,
banner_timeout=90,
allow_agent=False,
look_for_keys=False,
)
break
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2)
else:
raise SystemExit("ssh fail")
sftp = c.open_sftp()
with sftp.file("/tmp/_mem_balloon.py", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command(
f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_mem_balloon.py",
timeout=60,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
c.close()
if __name__ == "__main__":
main()