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
Quiet the broadcast ticker and allow larger poll worker pools
rcourtman3fe1f7f1819b
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 9f231a364a..5fe7988e50 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -2046,20 +2046,22 @@ func (m *Monitor) Start(ctx context.Context, wsHub *websocket.Hub) {case <-broadcastTicker.C:// Broadcast current state regardless of polling status- // Use GetState() instead of m.state.GetSnapshot() to respect mock mode- state := m.GetState()- log.Info().- Int("nodes", len(state.Nodes)).- Int("vms", len(state.VMs)).- Int("containers", len(state.Containers)).- Int("hosts", len(state.Hosts)).- Int("pbs", len(state.PBSInstances)).- Int("pbsBackups", len(state.Backups.PBS)).- Int("physicalDisks", len(state.PhysicalDisks)).- Msg("Broadcasting state update (ticker)")if !currentStateBroadcasterHasSubscribers(wsHub, m.GetOrgID()) {continue}+ if logging.IsLevelEnabled(zerolog.DebugLevel) {+ // Use GetState() instead of m.state.GetSnapshot() to respect mock mode+ state := m.GetState()+ log.Debug().+ Int("nodes", len(state.Nodes)).+ Int("vms", len(state.VMs)).+ Int("containers", len(state.Containers)).+ Int("hosts", len(state.Hosts)).+ Int("pbs", len(state.PBSInstances)).+ Int("pbsBackups", len(state.Backups.PBS)).+ Int("physicalDisks", len(state.PhysicalDisks)).+ Msg("Broadcasting state update (ticker)")+ }m.broadcastCurrentState(wsHub)case <-ctx.Done():@@ -2127,15 +2129,35 @@ func (m *Monitor) startTaskWorkers(ctx context.Context, workers int) {if m.taskQueue == nil {return}+ workers = resolveTaskWorkerCount(workers)+ for i := 0; i < workers; i++ {+ go m.taskWorker(ctx, i)+ }+}++// resolveTaskWorkerCount applies the default clamp of [1, 10] to the+// client-derived worker count. POLL_TASK_WORKERS overrides both the count and+// the cap for estates whose instance count outgrows the default pool; the+// override is bounded at 128 so a typo cannot fork an unbounded goroutine+// herd against the monitored APIs. Workers are I/O-bound, so the override+// spends sockets against monitored hosts, not local CPU.+func resolveTaskWorkerCount(workers int) int {+ if override := parseNonNegativeIntEnv("POLL_TASK_WORKERS", 0); override > 0 {+ if override > 128 {+ override = 128+ }+ log.Info().+ Int("workers", override).+ Msg("Poll task worker count overridden by POLL_TASK_WORKERS")+ return override+ }if workers < 1 {workers = 1}if workers > 10 {workers = 10}- for i := 0; i < workers; i++ {- go m.taskWorker(ctx, i)- }+ return workers}func (m *Monitor) taskWorker(ctx context.Context, id int) {diff --git a/internal/monitoring/monitor_start_workers_test.go b/internal/monitoring/monitor_start_workers_test.gonew file mode 100644index 0000000000..635e02da06--- /dev/null+++ b/internal/monitoring/monitor_start_workers_test.go@@ -0,0 +1,46 @@+package monitoring++import "testing"++func TestResolveTaskWorkerCountDefaultClamp(t *testing.T) {+ t.Setenv("POLL_TASK_WORKERS", "")++ cases := []struct {+ name string+ in int+ want int+ }{+ {name: "zero clients floors to one worker", in: 0, want: 1},+ {name: "negative floors to one worker", in: -3, want: 1},+ {name: "small estates keep their count", in: 4, want: 4},+ {name: "large estates cap at ten", in: 40, want: 10},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := resolveTaskWorkerCount(tc.in); got != tc.want {+ t.Fatalf("resolveTaskWorkerCount(%d) = %d, want %d", tc.in, got, tc.want)+ }+ })+ }+}++func TestResolveTaskWorkerCountEnvOverride(t *testing.T) {+ t.Setenv("POLL_TASK_WORKERS", "24")+ if got := resolveTaskWorkerCount(3); got != 24 {+ t.Fatalf("override ignored: got %d, want 24", got)+ }+}++func TestResolveTaskWorkerCountEnvOverrideCeiling(t *testing.T) {+ t.Setenv("POLL_TASK_WORKERS", "5000")+ if got := resolveTaskWorkerCount(3); got != 128 {+ t.Fatalf("override ceiling not applied: got %d, want 128", got)+ }+}++func TestResolveTaskWorkerCountInvalidOverrideFallsBack(t *testing.T) {+ t.Setenv("POLL_TASK_WORKERS", "not-a-number")+ if got := resolveTaskWorkerCount(40); got != 10 {+ t.Fatalf("invalid override should fall back to default clamp: got %d, want 10", got)+ }+}