mirror of
https://github.com/henrygd/beszel.git
synced 2026-05-06 10:51:50 +02:00
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
package probe
|
|
|
|
type SyncAction uint8
|
|
|
|
const (
|
|
// SyncActionReplace indicates a full sync where the provided configs should replace all existing probes for the system.
|
|
SyncActionReplace SyncAction = iota
|
|
// SyncActionUpsert indicates an incremental sync where the provided config should be added or updated.
|
|
SyncActionUpsert
|
|
// SyncActionDelete indicates an incremental sync where the provided config should be removed.
|
|
SyncActionDelete
|
|
)
|
|
|
|
// Config defines a network probe task sent from hub to agent.
|
|
type Config struct {
|
|
// ID is the stable network_probes record ID generated by the hub.
|
|
ID string `cbor:"0,keyasint"`
|
|
Target string `cbor:"1,keyasint"`
|
|
Protocol string `cbor:"2,keyasint"` // "icmp", "tcp", or "http"
|
|
Port uint16 `cbor:"3,keyasint,omitempty"`
|
|
Interval uint16 `cbor:"4,keyasint"` // seconds
|
|
}
|
|
|
|
// SyncRequest defines an incremental or full probe sync request sent to the agent.
|
|
type SyncRequest struct {
|
|
Action SyncAction `cbor:"0,keyasint"`
|
|
Config Config `cbor:"1,keyasint,omitempty"`
|
|
Configs []Config `cbor:"2,keyasint,omitempty"`
|
|
RunNow bool `cbor:"3,keyasint,omitempty"`
|
|
}
|
|
|
|
// SyncResponse returns the immediate result for an upsert when requested.
|
|
type SyncResponse struct {
|
|
Result Result `cbor:"0,keyasint,omitempty"`
|
|
}
|
|
|
|
// Result holds aggregated probe results for a single target.
|
|
//
|
|
// 0: avg response in microseconds
|
|
//
|
|
// 1: 1h average response in microseconds
|
|
//
|
|
// 2: min response in microseconds
|
|
//
|
|
// 3: 1h min response in microseconds
|
|
//
|
|
// 4: max response in microseconds
|
|
//
|
|
// 5: 1h max response in microseconds
|
|
//
|
|
// 6: packet loss percentage (0-100)
|
|
//
|
|
// 7: 1h packet loss percentage (0-100)
|
|
type Result struct {
|
|
AvgResponse int64 `cbor:"0,keyasint,omitempty"`
|
|
AvgResponse1h int64 `cbor:"1,keyasint,omitempty"`
|
|
MinResponse int64 `cbor:"2,keyasint,omitempty"`
|
|
MinResponse1h int64 `cbor:"3,keyasint,omitempty"`
|
|
MaxResponse int64 `cbor:"4,keyasint,omitempty"`
|
|
MaxResponse1h int64 `cbor:"5,keyasint,omitempty"`
|
|
PacketLoss float64 `cbor:"6,keyasint,omitempty"`
|
|
PacketLoss1h float64 `cbor:"7,keyasint,omitempty"`
|
|
}
|
|
|
|
// Stats holds only 1m values for a single target, which are used for charts.
|
|
//
|
|
// 0: avg response in microseconds
|
|
//
|
|
// 1: min response in microseconds
|
|
//
|
|
// 2: max response in microseconds
|
|
//
|
|
// 3: packet loss percentage (0-100)
|
|
type Stats []float64
|
|
|
|
func (s Stats) FromResult(result Result) Stats {
|
|
return Stats{
|
|
float64(result.AvgResponse),
|
|
float64(result.MinResponse),
|
|
float64(result.MaxResponse),
|
|
result.PacketLoss,
|
|
}
|
|
}
|