mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-21 08:57:48 +02:00
fix: resync network monitors after SSH reconnect and retry failed syncs
This commit is contained in:
@@ -2,6 +2,7 @@ package systems
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/henrygd/beszel"
|
||||
@@ -9,6 +10,27 @@ import (
|
||||
"github.com/henrygd/beszel/internal/entities/monitor"
|
||||
)
|
||||
|
||||
// syncPendingNetworkMonitors runs on WebSocket connect and after successful stats
|
||||
// fetches. Failed syncs retry on the next update without taking the system down.
|
||||
func (sys *System) syncPendingNetworkMonitors() {
|
||||
if !sys.monitorsNeedSync.Swap(false) {
|
||||
return
|
||||
}
|
||||
if err := sys.syncAllNetworkMonitors(); err != nil {
|
||||
sys.monitorsNeedSync.Store(true)
|
||||
sys.manager.hub.Logger().Warn("failed to sync monitors to agent", "system", sys.Id, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (sys *System) syncAllNetworkMonitors() error {
|
||||
configs, err := sys.manager.GetMonitorConfigsForSystem(sys.Id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load monitors: %w", err)
|
||||
}
|
||||
// An empty set must also replace probes retained across a disconnect.
|
||||
return sys.SyncNetworkMonitors(configs)
|
||||
}
|
||||
|
||||
// SyncNetworkMonitors sends monitor configurations to the agent.
|
||||
func (sys *System) SyncNetworkMonitors(configs []monitor.Config) error {
|
||||
_, err := sys.syncNetworkMonitors(monitor.SyncRequest{Action: monitor.SyncActionReplace, Configs: configs})
|
||||
|
||||
Reference in New Issue
Block a user