""" modules/dashboard.py — collects all live stats into one dict for GUI/HUD """ import psutil import platform import socket from modules.network_watch import get_ping GPU_OK = False try: from pynvml import nvmlInit, nvmlDeviceGetHandleByIndex from pynvml import nvmlDeviceGetTemperature, nvmlDeviceGetFanSpeed from pynvml import nvmlDeviceGetUtilizationRates, nvmlDeviceGetMemoryInfo, NVML_TEMPERATURE_GPU nvmlInit() GPU_OK = True except Exception: pass def get_snapshot() -> dict: cpu = psutil.cpu_percent(interval=0.3) ram = psutil.virtual_memory() disk = psutil.disk_usage("C:\\") if platform.system() == "Windows" else psutil.disk_usage("/") gpu_temp = gpu_util = gpu_fan = 0 gpu_vram = "N/A" if GPU_OK: try: h = nvmlDeviceGetHandleByIndex(0) gpu_temp = nvmlDeviceGetTemperature(h, NVML_TEMPERATURE_GPU) gpu_util = nvmlDeviceGetUtilizationRates(h).gpu gpu_fan = nvmlDeviceGetFanSpeed(h) mi = nvmlDeviceGetMemoryInfo(h) gpu_vram = f"{mi.used//1048576}/{mi.total//1048576} MB" except Exception: pass batt = None try: b = psutil.sensors_battery() if b: batt = {"percent": round(b.percent), "plugged": b.power_plugged} except Exception: pass net = psutil.net_io_counters() return { "hostname": socket.gethostname(), "os": platform.system() + " " + platform.release(), "cpu_pct": cpu, "ram_pct": ram.percent, "ram_used": ram.used // 1073741824, "ram_total": ram.total // 1073741824, "disk_free": disk.free // 1073741824, "disk_total":disk.total // 1073741824, "gpu_temp": gpu_temp, "gpu_util": gpu_util, "gpu_fan": gpu_fan, "gpu_vram": gpu_vram, "battery": batt, "net_sent": net.bytes_sent // 1024, "net_recv": net.bytes_recv // 1024, "ping": get_ping(), }