diff --git a/docs/VM_DISK_MONITORING.md b/docs/VM_DISK_MONITORING.md index dce6bb7..3cfc823 100644 --- a/docs/VM_DISK_MONITORING.md +++ b/docs/VM_DISK_MONITORING.md @@ -243,7 +243,7 @@ The agent reports all mounted filesystems. Pulse automatically filters out: - Special filesystems (proc, sys, tmpfs, devtmpfs, etc.) - Special Windows partitions ("System Reserved") - Bind mounts and overlays -- CD/DVD filesystems (iso9660, CDFS) +- Read-only appliance or optical images (squashfs, erofs, iso9660, CDFS, UDF, cramfs, romfs, fuse.cdfs) Only local disk usage is counted toward the VM's total. diff --git a/internal/monitoring/fs_filters.go b/internal/monitoring/fs_filters.go index e0bd355..efddb19 100644 --- a/internal/monitoring/fs_filters.go +++ b/internal/monitoring/fs_filters.go @@ -2,6 +2,19 @@ package monitoring import "strings" +var readOnlyFilesystemPatterns = []struct { + reason string + substrings []string +}{ + {reason: "erofs", substrings: []string{"erofs"}}, + {reason: "squashfs", substrings: []string{"squashfs", "squash-fs"}}, + {reason: "iso9660", substrings: []string{"iso9660"}}, + {reason: "cdfs", substrings: []string{"cdfs"}}, + {reason: "udf", substrings: []string{"udf"}}, + {reason: "cramfs", substrings: []string{"cramfs"}}, + {reason: "romfs", substrings: []string{"romfs"}}, +} + // readOnlyFilesystemReason returns a label explaining why a filesystem should be // ignored for usage calculations, along with a boolean indicating whether it is // a read-only filesystem that always reports full usage. This helps us avoid @@ -14,23 +27,12 @@ func readOnlyFilesystemReason(fsType string, totalBytes, usedBytes uint64) (stri } // Common read-only filesystem types used for immutable system partitions. - if strings.Contains(ft, "erofs") { - return "erofs", true - } - if strings.Contains(ft, "squashfs") || strings.Contains(ft, "squash-fs") { - return "squashfs", true - } - if strings.Contains(ft, "iso9660") { - return "iso9660", true - } - if strings.Contains(ft, "udf") { - return "udf", true - } - if strings.Contains(ft, "cramfs") { - return "cramfs", true - } - if strings.Contains(ft, "romfs") { - return "romfs", true + for _, pattern := range readOnlyFilesystemPatterns { + for _, needle := range pattern.substrings { + if strings.Contains(ft, needle) { + return pattern.reason, true + } + } } // Overlay-style filesystems can report 100% usage even though writes are diff --git a/internal/monitoring/fs_filters_test.go b/internal/monitoring/fs_filters_test.go index e309eab..352f19a 100644 --- a/internal/monitoring/fs_filters_test.go +++ b/internal/monitoring/fs_filters_test.go @@ -51,6 +51,54 @@ func TestReadOnlyFilesystemReason(t *testing.T) { reason: "squashfs", skip: true, }, + { + name: "iso9660 filesystem", + fsType: "iso9660", + totalBytes: 700 * 1024 * 1024, + usedBytes: 700 * 1024 * 1024, + reason: "iso9660", + skip: true, + }, + { + name: "cdfs filesystem", + fsType: "CDFS", + totalBytes: 600 * 1024 * 1024, + usedBytes: 600 * 1024 * 1024, + reason: "cdfs", + skip: true, + }, + { + name: "udf optical media", + fsType: "udf", + totalBytes: 4 * 1024 * 1024 * 1024, + usedBytes: 4 * 1024 * 1024 * 1024, + reason: "udf", + skip: true, + }, + { + name: "cramfs image", + fsType: "cramfs", + totalBytes: 128 * 1024 * 1024, + usedBytes: 128 * 1024 * 1024, + reason: "cramfs", + skip: true, + }, + { + name: "romfs firmware partition", + fsType: "romfs", + totalBytes: 16 * 1024 * 1024, + usedBytes: 16 * 1024 * 1024, + reason: "romfs", + skip: true, + }, + { + name: "fuse iso image", + fsType: "fuse.cdfs", + totalBytes: 700 * 1024 * 1024, + usedBytes: 700 * 1024 * 1024, + reason: "cdfs", + skip: true, + }, { name: "overlay below capacity", fsType: "overlay",