import paramiko
k = paramiko.Ed25519Key.from_private_key_file(r'C:\Users\fabia\.ssh\id_ed25519')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('192.168.178.150', username='fabian', pkey=k, timeout=10)
sftp = c.open_sftp()

# Full log
with sftp.open('/tmp/comfyui.log', 'r') as f:
    log = f.read().decode(errors='replace')
for line in log.split('\n'):
    s = line.strip()
    if not s or 'FETCH' in s or 'startup tasks' in s or 'DEPRECATION' in s: continue
    print(s)

# Process + GPU
chan = c.get_transport().open_session()
chan.settimeout(10)
chan.exec_command('/bin/bash -c "echo === PROC ===; ps aux | grep main.py | grep -v grep; echo === GPU ===; rocm-smi 2>/dev/null | head -12; echo === VRAM ===; rocm-smi --showmeminfo vram 2>/dev/null"')
o = b""
while True:
    try:
        ch = chan.recv(65536)
        if not ch: break
        o += ch
    except: break
chan.close()
print(o.decode(errors='replace'))

sftp.close()
c.close()
