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
feat: Add disk exclusion filter for host agent. Closes #896
rcourtmanc1422882bdd5
diff --git a/cmd/pulse-agent/main.go b/cmd/pulse-agent/main.goindex b84d971ba8..397302addc 100644--- a/cmd/pulse-agent/main.go+++ b/cmd/pulse-agent/main.go@@ -135,6 +135,7 @@ func main() {EnableProxmox: cfg.EnableProxmox,ProxmoxType: cfg.ProxmoxType,EnableCommands: cfg.EnableCommands,+ DiskExclude: cfg.DiskExclude,}agent, err := hostagent.New(hostCfg)@@ -351,6 +352,9 @@ type Config struct {// SecurityEnableCommands bool // Enable command execution for AI auto-fix (disabled by default)+ // Disk filtering+ DiskExclude []string // Mount points or patterns to exclude from disk monitoring+// Health/metrics serverHealthAddr string@@ -390,6 +394,7 @@ func loadConfig() Config {envKubeIncludeAllPods := utils.GetenvTrim("PULSE_KUBE_INCLUDE_ALL_PODS")envKubeIncludeAllDeployments := utils.GetenvTrim("PULSE_KUBE_INCLUDE_ALL_DEPLOYMENTS")envKubeMaxPods := utils.GetenvTrim("PULSE_KUBE_MAX_PODS")+ envDiskExclude := utils.GetenvTrim("PULSE_DISK_EXCLUDE")// DefaultsdefaultInterval := 30 * time.Second@@ -455,6 +460,8 @@ func loadConfig() Config {flag.Var(&kubeIncludeNamespaceFlags, "kube-include-namespace", "Namespace to include (repeatable; default is all)")var kubeExcludeNamespaceFlags multiValueflag.Var(&kubeExcludeNamespaceFlags, "kube-exclude-namespace", "Namespace to exclude (repeatable)")+ var diskExcludeFlags multiValue+ flag.Var(&diskExcludeFlags, "disk-exclude", "Mount point or path prefix to exclude from disk monitoring (repeatable)")flag.Parse()@@ -483,6 +490,7 @@ func loadConfig() Config {tags := gatherTags(envTags, tagFlags)kubeIncludeNamespaces := gatherCSV(envKubeIncludeNamespaces, kubeIncludeNamespaceFlags)kubeExcludeNamespaces := gatherCSV(envKubeExcludeNamespaces, kubeExcludeNamespaceFlags)+ diskExclude := gatherCSV(envDiskExclude, diskExcludeFlags)// Check if Docker was explicitly configured via flag or envdockerConfigured := envEnableDocker != ""@@ -519,6 +527,7 @@ func loadConfig() Config {KubeIncludeAllPods: *kubeIncludeAllPodsFlag,KubeIncludeAllDeployments: *kubeIncludeAllDeploymentsFlag,KubeMaxPods: *kubeMaxPodsFlag,+ DiskExclude: diskExclude,}}diff --git a/internal/dockeragent/agent.go b/internal/dockeragent/agent.goindex 63430dd934..1b7225b8c2 100644--- a/internal/dockeragent/agent.go+++ b/internal/dockeragent/agent.go@@ -684,7 +684,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) {uptime := readSystemUptime()metricsCtx, metricsCancel := context.WithTimeout(ctx, 10*time.Second)- snapshot, err := hostmetrics.Collect(metricsCtx)+ snapshot, err := hostmetrics.Collect(metricsCtx, nil)metricsCancel()if err != nil {return agentsdocker.Report{}, fmt.Errorf("collect host metrics: %w", err)diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.goindex 8bd5091450..4d9f8f3404 100644--- a/internal/hostagent/agent.go+++ b/internal/hostagent/agent.go@@ -48,6 +48,9 @@ type Config struct {// Security optionsEnableCommands bool // If true, enables the command execution feature (AI auto-fix)++ // Disk filtering+ DiskExclude []string // Mount points or path prefixes to exclude from disk monitoring}// Agent is responsible for collecting host metrics and shipping them to Pulse.@@ -340,7 +343,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) {defer cancel()uptime, _ := hostUptimeWithContext(collectCtx)- snapshot, err := hostmetricsCollect(collectCtx)+ snapshot, err := hostmetricsCollect(collectCtx, a.cfg.DiskExclude)if err != nil {return agentshost.Report{}, fmt.Errorf("collect metrics: %w", err)}diff --git a/internal/hostmetrics/collector.go b/internal/hostmetrics/collector.goindex 6f1bd38ee5..b03954b8e3 100644--- a/internal/hostmetrics/collector.go+++ b/internal/hostmetrics/collector.go@@ -41,7 +41,8 @@ type Snapshot struct {}// Collect gathers a point-in-time snapshot of host resource utilisation.-func Collect(ctx context.Context) (Snapshot, error) {+// diskExclude contains user-defined patterns for mount points to exclude.+func Collect(ctx context.Context, diskExclude []string) (Snapshot, error) {collectCtx, cancel := context.WithTimeout(ctx, 10*time.Second)defer cancel()@@ -78,7 +79,7 @@ func Collect(ctx context.Context) (Snapshot, error) {SwapUsed: swapUsed,}- snapshot.Disks = collectDisks(collectCtx)+ snapshot.Disks = collectDisks(collectCtx, diskExclude)snapshot.DiskIO = collectDiskIO(collectCtx)snapshot.Network = collectNetwork(collectCtx)@@ -104,7 +105,7 @@ func collectCPUUsage(ctx context.Context) (float64, error) {return usage, nil}-func collectDisks(ctx context.Context) []agentshost.Disk {+func collectDisks(ctx context.Context, diskExclude []string) []agentshost.Disk {partitions, err := diskPartitions(ctx, true)if err != nil {return nil@@ -123,6 +124,11 @@ func collectDisks(ctx context.Context) []agentshost.Disk {}seen[part.Mountpoint] = struct{}{}+ // Check user-defined exclusions first (issue #896)+ if fsfilters.MatchesUserExclude(part.Mountpoint, diskExclude) {+ continue+ }+usage, err := diskUsage(ctx, part.Mountpoint)if err != nil {continuediff --git a/internal/hostmetrics/collector_test.go b/internal/hostmetrics/collector_test.goindex 453c334695..232f8623c9 100644--- a/internal/hostmetrics/collector_test.go+++ b/internal/hostmetrics/collector_test.go@@ -9,7 +9,7 @@ import (func TestCollectDiskIO(t *testing.T) {ctx := context.Background()- snapshot, err := Collect(ctx)+ snapshot, err := Collect(ctx, nil)if err != nil {t.Fatalf("Collect failed: %v", err)}diff --git a/pkg/fsfilters/filters.go b/pkg/fsfilters/filters.goindex 26656324d4..7ea2841c60 100644--- a/pkg/fsfilters/filters.go+++ b/pkg/fsfilters/filters.go@@ -183,3 +183,46 @@ func ShouldSkipFilesystem(fsType, mountpoint string, totalBytes, usedBytes uint6return len(reasons) > 0, reasons}++// MatchesUserExclude checks if a mountpoint matches any user-defined exclusion patterns.+// Patterns can be:+// - Exact paths: "/mnt/backup" matches only "/mnt/backup"+// - Prefix patterns (ending with *): "/mnt/ext*" matches "/mnt/external", "/mnt/ext-drive"+// - Contains patterns (surrounded by *): "*pbs*" matches any path containing "pbs"+func MatchesUserExclude(mountpoint string, excludePatterns []string) bool {+ if len(excludePatterns) == 0 {+ return false+ }++ for _, pattern := range excludePatterns {+ pattern = strings.TrimSpace(pattern)+ if pattern == "" {+ continue+ }++ // Contains pattern: *substring*+ if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") && len(pattern) > 2 {+ substring := pattern[1 : len(pattern)-1]+ if strings.Contains(mountpoint, substring) {+ return true+ }+ continue+ }++ // Prefix pattern: /path/prefix*+ if strings.HasSuffix(pattern, "*") {+ prefix := pattern[:len(pattern)-1]+ if strings.HasPrefix(mountpoint, prefix) {+ return true+ }+ continue+ }++ // Exact match+ if mountpoint == pattern {+ return true+ }+ }++ return false+}diff --git a/pkg/fsfilters/filters_test.go b/pkg/fsfilters/filters_test.goindex 12989077fd..ca5fd9439b 100644--- a/pkg/fsfilters/filters_test.go+++ b/pkg/fsfilters/filters_test.go@@ -216,3 +216,52 @@ func TestShouldSkipFilesystem(t *testing.T) {})}}++func TestMatchesUserExclude(t *testing.T) {+ tests := []struct {+ name string+ mountpoint string+ patterns []string+ expected bool+ }{+ // Exact match+ {"exact match", "/mnt/backup", []string{"/mnt/backup"}, true},+ {"exact no match", "/mnt/backup", []string{"/mnt/data"}, false},+ {"exact case sensitive", "/mnt/Backup", []string{"/mnt/backup"}, false},++ // Prefix patterns (ending with *)+ {"prefix match", "/mnt/external", []string{"/mnt/ext*"}, true},+ {"prefix match long", "/mnt/external-drive-2", []string{"/mnt/ext*"}, true},+ {"prefix no match", "/home/user", []string{"/mnt/ext*"}, false},++ // Contains patterns (*substring*)+ {"contains match", "/mnt/pbs-data", []string{"*pbs*"}, true},+ {"contains match middle", "/data/pbs/backup", []string{"*pbs*"}, true},+ {"contains no match", "/mnt/data", []string{"*pbs*"}, false},++ // Multiple patterns+ {"multiple patterns first match", "/mnt/backup", []string{"/mnt/backup", "/data/*"}, true},+ {"multiple patterns second match", "/data/files", []string{"/mnt/backup", "/data/*"}, true},+ {"multiple patterns no match", "/home/user", []string{"/mnt/backup", "/data/*"}, false},++ // Edge cases+ {"empty patterns", "/mnt/backup", []string{}, false},+ {"nil patterns", "/mnt/backup", nil, false},+ {"empty pattern in list", "/mnt/backup", []string{"", "/mnt/backup"}, true},+ {"whitespace pattern", "/mnt/backup", []string{" /mnt/backup "}, true},++ // Real-world use cases (Issue #896)+ {"exclude pbs mount", "/mnt/pbs-datastore", []string{"*pbs*"}, true},+ {"exclude specific mount", "/media/external-hdd", []string{"/media/external-hdd"}, true},+ {"exclude all media mounts", "/media/usb-drive", []string{"/media/*"}, true},+ }++ for _, tc := range tests {+ t.Run(tc.name, func(t *testing.T) {+ result := MatchesUserExclude(tc.mountpoint, tc.patterns)+ if result != tc.expected {+ t.Errorf("MatchesUserExclude(%q, %v) = %t, want %t", tc.mountpoint, tc.patterns, result, tc.expected)+ }+ })+ }+}