This commit is contained in:
henrygd
2026-04-23 01:13:01 -04:00
parent 5fc774666f
commit 0d440e5fb9
8 changed files with 390 additions and 127 deletions

View File

@@ -371,21 +371,21 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst
var record *core.Record
record, err = app.FindRecordById(collectionName, id)
if err == nil {
record.Set("res", probeMetric(values, 0))
record.Set("resAvg1h", probeMetric(values, 1))
record.Set("resMin1h", probeMetric(values, 2))
record.Set("resMax1h", probeMetric(values, 3))
record.Set("loss1h", probeMetric(values, 4))
record.Set("res", values.Get(0))
record.Set("resAvg1h", values.Get(1))
record.Set("resMin1h", values.Get(2))
record.Set("resMax1h", values.Get(3))
record.Set("loss1h", values.Get(4))
err = app.SaveNoValidate(record)
}
default:
_, err = updateQuery.Bind(dbx.Params{
"id": id,
"res": probeMetric(values, 0),
"resAvg1h": probeMetric(values, 1),
"resMin1h": probeMetric(values, 2),
"resMax1h": probeMetric(values, 3),
"loss1h": probeMetric(values, 4),
"res": values.Get(0),
"resAvg1h": values.Get(1),
"resMin1h": values.Get(2),
"resMax1h": values.Get(3),
"loss1h": values.Get(4),
"updated": nowString,
}).Execute()
}
@@ -397,13 +397,6 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst
return nil
}
func probeMetric(values probe.Result, index int) float64 {
if index < len(values) {
return values[index]
}
return 0
}
// createContainerRecords creates container records
func createContainerRecords(app core.App, data []*container.Stats, systemId string) error {
if len(data) == 0 {

View File

@@ -10,48 +10,39 @@ import (
// SyncNetworkProbes sends probe configurations to the agent.
func (sys *System) SyncNetworkProbes(configs []probe.Config) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
var result string
return sys.request(ctx, common.SyncNetworkProbes, configs, &result)
_, err := sys.syncNetworkProbes(probe.SyncRequest{Action: probe.SyncActionReplace, Configs: configs})
return err
}
// FetchNetworkProbeResults fetches probe results from the agent.
// func (sys *System) FetchNetworkProbeResults() (map[string]probe.Result, error) {
// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
// defer cancel()
// var results map[string]probe.Result
// err := sys.request(ctx, common.GetNetworkProbeResults, nil, &results)
// return results, err
// }
// UpsertNetworkProbe sends a single probe configuration change to the agent.
func (sys *System) UpsertNetworkProbe(config probe.Config, runNow bool) (*probe.Result, error) {
resp, err := sys.syncNetworkProbes(probe.SyncRequest{
Action: probe.SyncActionUpsert,
Config: config,
RunNow: runNow,
})
if err != nil {
return nil, err
}
if len(resp.Result) == 0 {
return nil, nil
}
result := resp.Result
return &result, nil
}
// hasEnabledProbes returns true if this system has any enabled network probes.
// func (sys *System) hasEnabledProbes() bool {
// count, err := sys.manager.hub.CountRecords("network_probes",
// dbx.NewExp("system = {:system} AND enabled = true", dbx.Params{"system": sys.Id}))
// return err == nil && count > 0
// }
// DeleteNetworkProbe removes a single probe task from the agent.
func (sys *System) DeleteNetworkProbe(id string) error {
_, err := sys.syncNetworkProbes(probe.SyncRequest{
Action: probe.SyncActionDelete,
Config: probe.Config{ID: id},
})
return err
}
// fetchAndSaveProbeResults fetches probe results and saves them to the database.
// func (sys *System) fetchAndSaveProbeResults() {
// hub := sys.manager.hub
// results, err := sys.FetchNetworkProbeResults()
// if err != nil || len(results) == 0 {
// return
// }
// collection, err := hub.FindCachedCollectionByNameOrId("network_probe_stats")
// if err != nil {
// return
// }
// record := core.NewRecord(collection)
// record.Set("system", sys.Id)
// record.Set("stats", results)
// record.Set("type", "1m")
// if err := hub.SaveNoValidate(record); err != nil {
// hub.Logger().Warn("failed to save probe stats", "system", sys.Id, "err", err)
// }
// }
func (sys *System) syncNetworkProbes(req probe.SyncRequest) (probe.SyncResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
var result probe.SyncResponse
return result, sys.request(ctx, common.SyncNetworkProbes, req, &result)
}