mirror of
https://github.com/henrygd/beszel.git
synced 2026-05-06 19:01:48 +02:00
updates
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package hub
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/henrygd/beszel/internal/entities/probe"
|
||||
"github.com/henrygd/beszel/internal/hub/systems"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
// generateProbeID creates a stable hash ID for a probe based on its configuration and the system it belongs to.
|
||||
@@ -107,11 +110,14 @@ func probeConfigFromRecord(record *core.Record) *probe.Config {
|
||||
|
||||
// setProbeResultFields stores the latest probe result values on the record.
|
||||
func setProbeResultFields(record *core.Record, result probe.Result) {
|
||||
now := time.Now().UTC()
|
||||
nowString := now.Format(types.DefaultDateLayout)
|
||||
record.Set("res", result.Get(0))
|
||||
record.Set("resAvg1h", result.Get(1))
|
||||
record.Set("resMin1h", result.Get(2))
|
||||
record.Set("resMax1h", result.Get(3))
|
||||
record.Set("loss1h", result.Get(4))
|
||||
record.Set("updated", nowString)
|
||||
}
|
||||
|
||||
// copyProbeToNewRecord creates a new record with the same field values as the old one.
|
||||
|
||||
@@ -327,12 +327,13 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst
|
||||
return !strings.Contains(filterQuery, "system") || strings.Contains(filterQuery, systemId)
|
||||
})
|
||||
|
||||
now := time.Now().UTC()
|
||||
nowMilli := now.UnixMilli()
|
||||
nowString := now.Format(types.DefaultDateLayout)
|
||||
var db dbx.Builder
|
||||
var nowString string
|
||||
var updateQuery *dbx.Query
|
||||
if !realtimeActive {
|
||||
db = app.DB()
|
||||
nowString = time.Now().UTC().Format(types.DefaultDateLayout)
|
||||
sql := fmt.Sprintf("UPDATE %s SET res={:res}, resMin1h={:resMin1h}, resMax1h={:resMax1h}, resAvg1h={:resAvg1h}, loss1h={:loss1h}, updated={:updated} WHERE id={:id}", collectionName)
|
||||
updateQuery = db.NewQuery(sql)
|
||||
}
|
||||
@@ -349,6 +350,7 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst
|
||||
record.Set("resMin1h", values.Get(2))
|
||||
record.Set("resMax1h", values.Get(3))
|
||||
record.Set("loss1h", values.Get(4))
|
||||
record.Set("updated", nowString)
|
||||
err = app.SaveNoValidate(record)
|
||||
}
|
||||
default:
|
||||
@@ -375,6 +377,7 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst
|
||||
record.Set("system", systemId)
|
||||
record.Set("stats", data)
|
||||
record.Set("type", "1m")
|
||||
record.Set("created", nowMilli)
|
||||
err = app.SaveNoValidate(record)
|
||||
default:
|
||||
var statsJson types.JSONRaw
|
||||
@@ -384,7 +387,7 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst
|
||||
"system": systemId,
|
||||
"stats": statsJson,
|
||||
"type": "1m",
|
||||
"created": nowString,
|
||||
"created": nowMilli,
|
||||
}).Execute()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user