Skip to content

Commit

Permalink
Simplify gathering disk usage metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Nov 28, 2024
1 parent e86b450 commit 2e9bd9a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pyninja/monitor/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,16 @@ async def websocket_endpoint(websocket: WebSocket, session_token: str = Cookie(N
all_disks = disks.get_all_disks()
disk_info = []
for disk in all_disks:
total, used, free = (0, 0, 0)
disk_usage_totals = {"total": 0, "used": 0, "free": 0}
disk_usage = {"name": disk.get("Name"), "id": disk.get("DeviceID")}
mountpoints = (
disk.get("Mountpoints", "").split(", ") if disk.get("Mountpoints") else []
)
for mountpoint in mountpoints:
part_usage = shutil.disk_usage(mountpoint)
total += part_usage.total
used += part_usage.used
free += part_usage.free
disk_usage.update({"total": total, "used": used, "free": free})
for key in disk_usage_totals:
disk_usage_totals[key] += getattr(part_usage, key)
disk_usage.update(disk_usage_totals)
disk_info.append(disk_usage)
while True:
# Validate session asynchronously (non-blocking)
Expand Down

0 comments on commit 2e9bd9a

Please sign in to comment.