This commit is contained in:
henrygd
2026-04-19 21:44:21 -04:00
parent ea19ef6334
commit e71ffd4d2a
15 changed files with 136 additions and 113 deletions

View File

@@ -48,7 +48,7 @@ type Agent struct {
keys []gossh.PublicKey // SSH public keys
smartManager *SmartManager // Manages SMART data
systemdManager *systemdManager // Manages systemd services
probeManager *ProbeManager // Manages network probes
probeManager *ProbeManager // Manages network probes
}
// NewAgent creates a new agent with the given data directory for persisting data.
@@ -182,6 +182,11 @@ func (a *Agent) gatherStats(options common.DataRequestOptions) *system.CombinedD
}
}
if a.probeManager != nil {
data.Probes = a.probeManager.GetResults()
slog.Debug("Probes", "data", data.Probes)
}
// skip updating systemd services if cache time is not the default 60sec interval
if a.systemdManager != nil && cacheTimeMs == defaultDataCacheTimeMs {
totalCount := uint16(a.systemdManager.getServiceStatsCount())

View File

@@ -53,7 +53,6 @@ func NewHandlerRegistry() *HandlerRegistry {
registry.Register(common.GetSmartData, &GetSmartDataHandler{})
registry.Register(common.GetSystemdInfo, &GetSystemdInfoHandler{})
registry.Register(common.SyncNetworkProbes, &SyncNetworkProbesHandler{})
registry.Register(common.GetNetworkProbeResults, &GetNetworkProbeResultsHandler{})
return registry
}
@@ -222,14 +221,3 @@ func (h *SyncNetworkProbesHandler) Handle(hctx *HandlerContext) error {
slog.Info("network probes synced", "count", len(configs))
return hctx.SendResponse("ok", hctx.RequestID)
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// GetNetworkProbeResultsHandler handles probe results request from hub
type GetNetworkProbeResultsHandler struct{}
func (h *GetNetworkProbeResultsHandler) Handle(hctx *HandlerContext) error {
results := hctx.Agent.probeManager.GetResults()
return hctx.SendResponse(results, hctx.RequestID)
}

View File

@@ -120,10 +120,10 @@ func (pm *ProbeManager) GetResults() map[string]probe.Result {
}
results[key] = probe.Result{
AvgMs: avg,
MinMs: math.Round(minMs*100) / 100,
MaxMs: math.Round(maxMs*100) / 100,
Loss: math.Round(float64(lossCount)/float64(count)*10000) / 100,
avg, // average latency in ms
math.Round(minMs*100) / 100, // min latency in ms
math.Round(maxMs*100) / 100, // max latency in ms
math.Round(float64(lossCount)/float64(count)*10000) / 100, // packet loss percentage
}
}