Use Python disk_usage for Windows storage metrics

This commit is contained in:
2025-08-13 03:13:32 -06:00
parent 00792c5b10
commit 396b15aa4c

View File

@@ -17,6 +17,8 @@ import time # Heartbeat timestamps
import subprocess
import getpass
import datetime
import shutil
import string
import requests
try:
@@ -469,6 +471,24 @@ def collect_storage():
"used": usage.used,
})
elif plat == "windows":
found = False
for letter in string.ascii_uppercase:
drive = f"{letter}:\\"
if os.path.exists(drive):
try:
usage = shutil.disk_usage(drive)
except Exception:
continue
disks.append({
"drive": drive,
"disk_type": "Fixed Disk",
"usage": (usage.used / usage.total * 100) if usage.total else 0,
"total": usage.total,
"free": usage.free,
"used": usage.used,
})
found = True
if not found:
try:
out = subprocess.run(
["wmic", "logicaldisk", "get", "DeviceID,Size,FreeSpace"],