monitoring: streamline storage dashboard to single time series panel and filter real host mounts

This commit is contained in:
mamad
2026-08-28 19:43:05 +03:30
parent ad4c111318
commit ad8df0bdc9
2 changed files with 33 additions and 165 deletions
+27 -22
View File
@@ -115,33 +115,18 @@ VOLUME_DEFINITIONS = [
{
"mountpoint": "/",
"device": "/dev/sda1",
"container_paths": ["/host_os/home", "/hostfs/host_mnt/home", "/home", "/host_os_disk", "/hostfs", "/"]
"container_paths": ["/host_os/home", "/home"]
},
{
"mountpoint": "/projects",
"device": "/dev/sda2",
"container_paths": ["/host_os/projects", "/projects"]
},
{
"mountpoint": "/boot",
"device": "/dev/sda4",
"container_paths": ["/host_os/boot", "/boot"]
},
{
"mountpoint": "/boot/efi",
"device": "/dev/sda3",
"container_paths": ["/host_os/boot_efi", "/boot/efi"]
},
{
"mountpoint": "/run/media/mamad/WIN11_25H2_",
"device": "/dev/sdc1",
"container_paths": ["/host_os/media/mamad/WIN11_25H2_", "/run/media/mamad/WIN11_25H2_"]
}
]
def update_disk_metrics():
"""Update Prometheus gauges with real host OS filesystem disk usage for each mounted volume."""
"""Update Prometheus gauges with real host OS filesystem disk usage for verified mounted volumes."""
try:
recorded_mounts = set()
for v in VOLUME_DEFINITIONS:
@@ -161,14 +146,34 @@ def update_disk_metrics():
except Exception as err:
logger.debug(f"Error measuring disk usage for {path}: {err}")
# If none of the specific mounts matched, fallback to root
# Dynamically check any mounted external media drives under /host_os/media
media_root = "/host_os/media"
if os.path.exists(media_root) and os.path.isdir(media_root):
try:
for user in os.listdir(media_root):
user_dir = os.path.join(media_root, user)
if os.path.isdir(user_dir):
for drive in os.listdir(user_dir):
drive_path = os.path.join(user_dir, drive)
if os.path.isdir(drive_path):
total, used, free = shutil.disk_usage(drive_path)
mnt_label = f"/run/media/{user}/{drive}"
DISK_TOTAL_BYTES.labels(mountpoint=mnt_label, device="external").set(total)
DISK_USED_BYTES.labels(mountpoint=mnt_label, device="external").set(used)
DISK_FREE_BYTES.labels(mountpoint=mnt_label, device="external").set(free)
free_pct = (free / total * 100.0) if total > 0 else 0.0
DISK_FREE_PERCENT.labels(mountpoint=mnt_label, device="external").set(free_pct)
except Exception as e:
logger.debug(f"Error scanning external media mounts: {e}")
# If neither specific mount matched, fallback to root
if not recorded_mounts:
total, used, free = shutil.disk_usage("/")
DISK_TOTAL_BYTES.labels(mountpoint="/", device="default").set(total)
DISK_USED_BYTES.labels(mountpoint="/", device="default").set(used)
DISK_FREE_BYTES.labels(mountpoint="/", device="default").set(free)
DISK_TOTAL_BYTES.labels(mountpoint="/", device="/dev/sda1").set(total)
DISK_USED_BYTES.labels(mountpoint="/", device="/dev/sda1").set(used)
DISK_FREE_BYTES.labels(mountpoint="/", device="/dev/sda1").set(free)
free_pct = (free / total * 100.0) if total > 0 else 0.0
DISK_FREE_PERCENT.labels(mountpoint="/", device="default").set(free_pct)
DISK_FREE_PERCENT.labels(mountpoint="/", device="/dev/sda1").set(free_pct)
except Exception as e:
logger.debug(f"Error updating host disk metrics: {e}")