fix: exclude virtual/pseudo filesystems from disk metrics

squashfs loop mounts (snap packages) are always 100% full by design and
were skewing the max disk usage shown in the UI. Now filters the same
set of pseudo-filesystems that 'df' excludes by default, plus any
/dev/loop* devices regardless of fstype.
This commit is contained in:
Joel Male
2026-02-25 14:57:16 +10:00
parent c9f6f282a6
commit c0541f7bc9
+42
View File
@@ -744,6 +744,45 @@ func collectAndSend(config *Config) {
log.Printf("Successfully sent metrics at %s", time.Now().Format(time.RFC3339)) log.Printf("Successfully sent metrics at %s", time.Now().Format(time.RFC3339))
} }
// virtualFSTypes are filesystem types that should be excluded from disk
// reporting — pseudo, read-only, or kernel-managed mounts that aren't
// real storage (snap loop devices, tmpfs, container overlays, etc.).
var virtualFSTypes = map[string]bool{
"squashfs": true, // snap packages — always 100% full
"tmpfs": true,
"devtmpfs": true,
"ramfs": true,
"overlay": true,
"overlayfs": true,
"proc": true,
"sysfs": true,
"devfs": true,
"cgroup": true,
"cgroup2": true,
"pstore": true,
"efivarfs": true,
"bpf": true,
"fusectl": true,
"hugetlbfs": true,
"mqueue": true,
"debugfs": true,
"tracefs": true,
"securityfs": true,
"configfs": true,
"autofs": true,
}
func isVirtualFS(fstype, device string) bool {
if virtualFSTypes[fstype] {
return true
}
// Loop devices back read-only images (snaps, ISOs, etc.)
if strings.HasPrefix(device, "/dev/loop") {
return true
}
return false
}
func collectMetrics(config *Config) (*Metrics, error) { func collectMetrics(config *Config) (*Metrics, error) {
metrics := &Metrics{ metrics := &Metrics{
Timestamp: time.Now().UTC(), Timestamp: time.Now().UTC(),
@@ -847,6 +886,9 @@ func collectMetrics(config *Config) (*Metrics, error) {
return nil, fmt.Errorf("failed to get disk partitions: %w", err) return nil, fmt.Errorf("failed to get disk partitions: %w", err)
} }
for _, p := range partitions { for _, p := range partitions {
if isVirtualFS(p.Fstype, p.Device) {
continue
}
usage, err := disk.Usage(p.Mountpoint) usage, err := disk.Usage(p.Mountpoint)
if err != nil { if err != nil {
continue continue