Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(hostmetrics): skip network mounts before usage probe (#1313)
rcourtmanac83074fc2b0
diff --git a/internal/hostmetrics/collector.go b/internal/hostmetrics/collector.goindex e45c2a37dd..d212ff1786 100644--- a/internal/hostmetrics/collector.go+++ b/internal/hostmetrics/collector.go@@ -169,6 +169,16 @@ func collectDisks(ctx context.Context, diskExclude []string) []agentshost.Disk {continue}+ isZFSMount := strings.EqualFold(part.Fstype, "zfs") || strings.EqualFold(part.Fstype, "fuse.zfs")++ // Filter mounts that should never be counted before probing usage stats.+ // This avoids potentially blocking statfs calls on stale/unreachable network mounts.+ if !isZFSMount {+ if shouldSkip, _ := fsfilters.ShouldSkipFilesystemBeforeUsage(part.Fstype, part.Mountpoint); shouldSkip {+ continue+ }+ }+usage, err := diskUsage(ctx, part.Mountpoint)if err != nil {log.Debug().Err(err).Str("mount", part.Mountpoint).Str("device", part.Device).Str("fstype", part.Fstype).Msg("disk: failed to get usage")@@ -179,7 +189,7 @@ func collectDisks(ctx context.Context, diskExclude []string) []agentshost.Disk {continue}- if strings.EqualFold(part.Fstype, "zfs") || strings.EqualFold(part.Fstype, "fuse.zfs") {+ if isZFSMount {pool := zfsPoolFromDevice(part.Device)if pool == "" {log.Debug().Str("device", part.Device).Str("mount", part.Mountpoint).Msg("disk: zfs partition with empty pool name, skipping")diff --git a/internal/hostmetrics/collector_test.go b/internal/hostmetrics/collector_test.goindex 5899ed6940..6a94679696 100644--- a/internal/hostmetrics/collector_test.go+++ b/internal/hostmetrics/collector_test.go@@ -3,6 +3,7 @@ package hostmetricsimport ("context""encoding/json"+ "errors""testing"godisk "github.com/shirou/gopsutil/v4/disk"@@ -111,3 +112,90 @@ func TestCollectDisks_DeviceDeduplication(t *testing.T) {t.Errorf("Total storage should be %d bytes, got %d bytes", expectedTotal, total)}}++// TestCollectDisks_SkipsNetworkMountsBeforeUsageProbe verifies network filesystems+// are filtered before disk usage calls to prevent hangs on stale remote mounts.+func TestCollectDisks_SkipsNetworkMountsBeforeUsageProbe(t *testing.T) {+ origPartitions := diskPartitions+ origUsage := diskUsage+ defer func() {+ diskPartitions = origPartitions+ diskUsage = origUsage+ }()++ diskPartitions = func(ctx context.Context, all bool) ([]godisk.PartitionStat, error) {+ return []godisk.PartitionStat{+ {Device: "nas:/pool/share", Mountpoint: "/mnt/nas", Fstype: "nfs4"},+ {Device: "/dev/sda1", Mountpoint: "/", Fstype: "ext4"},+ }, nil+ }++ usageCalls := 0+ diskUsage = func(ctx context.Context, path string) (*godisk.UsageStat, error) {+ usageCalls+++ if path == "/mnt/nas" {+ t.Fatalf("diskUsage was called for network mount %q", path)+ }+ return &godisk.UsageStat{+ Total: 1000,+ Used: 400,+ Free: 600,+ UsedPercent: 40.0,+ }, nil+ }++ disks := collectDisks(context.Background(), nil)+ if usageCalls != 1 {+ t.Fatalf("expected diskUsage to be called once for local filesystems, got %d calls", usageCalls)+ }+ if len(disks) != 1 {+ t.Fatalf("expected 1 disk after skipping network mounts, got %d", len(disks))+ }+ if disks[0].Mountpoint != "/" {+ t.Fatalf("expected local root mount to remain, got %q", disks[0].Mountpoint)+ }+}++func TestCollectDisks_DoesNotPreSkipFuseZFS(t *testing.T) {+ origPartitions := diskPartitions+ origUsage := diskUsage+ origQuery := queryZpoolStats+ defer func() {+ diskPartitions = origPartitions+ diskUsage = origUsage+ queryZpoolStats = origQuery+ }()++ diskPartitions = func(ctx context.Context, all bool) ([]godisk.PartitionStat, error) {+ return []godisk.PartitionStat{+ {Device: "tank/data", Mountpoint: "/tank/data", Fstype: "fuse.zfs"},+ }, nil+ }++ usageCalls := 0+ diskUsage = func(ctx context.Context, path string) (*godisk.UsageStat, error) {+ usageCalls+++ return &godisk.UsageStat{+ Total: 1000,+ Used: 200,+ Free: 800,+ UsedPercent: 20.0,+ }, nil+ }++ // Force fallback path so this test does not depend on system zpool binaries.+ queryZpoolStats = func(ctx context.Context, pools []string) (map[string]zpoolStats, error) {+ return nil, errors.New("zpool unavailable in test")+ }++ disks := collectDisks(context.Background(), nil)+ if usageCalls != 1 {+ t.Fatalf("expected diskUsage to be called for fuse.zfs dataset, got %d calls", usageCalls)+ }+ if len(disks) != 1 {+ t.Fatalf("expected 1 summarized zfs disk, got %d", len(disks))+ }+ if disks[0].Filesystem != "zfs" {+ t.Fatalf("expected filesystem type zfs, got %q", disks[0].Filesystem)+ }+}diff --git a/pkg/fsfilters/filters.go b/pkg/fsfilters/filters.goindex 02612cb82b..e52bfc7ce2 100644--- a/pkg/fsfilters/filters.go+++ b/pkg/fsfilters/filters.go@@ -191,6 +191,14 @@ func ShouldSkipFilesystem(fsType, mountpoint string, totalBytes, usedBytes uint6return len(reasons) > 0, reasons}+// ShouldSkipFilesystemBeforeUsage determines whether a filesystem can be skipped+// using only metadata that is safe to read from mount tables (fstype + mountpoint).+// This is used before probing usage stats so the caller can avoid statfs/syscalls+// on mounts known to be excluded (for example stale/unreachable NFS mounts).+func ShouldSkipFilesystemBeforeUsage(fsType, mountpoint string) (skip bool, reasons []string) {+ return ShouldSkipFilesystem(fsType, mountpoint, 0, 0)+}+// MatchesUserExclude checks if a mountpoint matches any user-defined exclusion patterns.// Patterns can be:// - Exact paths: "/mnt/backup" matches only "/mnt/backup"diff --git a/pkg/fsfilters/filters_test.go b/pkg/fsfilters/filters_test.goindex 708e9c2865..e7e806d66c 100644--- a/pkg/fsfilters/filters_test.go+++ b/pkg/fsfilters/filters_test.go@@ -226,6 +226,43 @@ func TestShouldSkipFilesystem(t *testing.T) {}}+func TestShouldSkipFilesystemBeforeUsage(t *testing.T) {+ tests := []struct {+ name string+ fsType string+ mountpoint string+ expectSkip bool+ }{+ {+ name: "network mount is skipped before usage probe",+ fsType: "nfs4",+ mountpoint: "/mnt/nas",+ expectSkip: true,+ },+ {+ name: "regular local filesystem is kept for usage probe",+ fsType: "ext4",+ mountpoint: "/",+ expectSkip: false,+ },+ {+ name: "special mountpoint is skipped before usage probe",+ fsType: "ext4",+ mountpoint: "/run/user/1000",+ expectSkip: true,+ },+ }++ for _, tc := range tests {+ t.Run(tc.name, func(t *testing.T) {+ skip, _ := ShouldSkipFilesystemBeforeUsage(tc.fsType, tc.mountpoint)+ if skip != tc.expectSkip {+ t.Errorf("expected skip=%t, got skip=%t", tc.expectSkip, skip)+ }+ })+ }+}+func TestMatchesUserExclude(t *testing.T) {tests := []struct {name string