29 lines
710 B
Python
29 lines
710 B
Python
import psutil
|
|
import subprocess
|
|
import time
|
|
|
|
print("Monitoring system usage. Press Ctrl+C to stop.\n")
|
|
|
|
try:
|
|
while True:
|
|
cpu = psutil.cpu_percent(interval=1)
|
|
ram = psutil.virtual_memory().used / (1024 * 1024)
|
|
|
|
result = subprocess.check_output([
|
|
"nvidia-smi",
|
|
"--query-gpu=utilization.gpu,memory.used",
|
|
"--format=csv,noheader,nounits"
|
|
], text=True).strip()
|
|
|
|
gpu, vram = result.split(",")
|
|
|
|
print(
|
|
f"CPU: {cpu:5.1f}% | "
|
|
f"RAM: {ram:7.0f} MB | "
|
|
f"GPU: {gpu.strip():>3}% | "
|
|
f"VRAM: {vram.strip():>5} MB"
|
|
)
|
|
|
|
except KeyboardInterrupt:
|
|
print("\nMonitoring stopped.")
|