mirror of
https://github.com/henrygd/beszel.git
synced 2026-05-06 10:51:50 +02:00
83 lines
2.3 KiB
Go
83 lines
2.3 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 []float64
|
|
|
|
// Get returns the value at the specified index or 0 if the index is out of range.
|
|
func (r Result) Get(index int) float64 {
|
|
if index < len(r) {
|
|
return r[index]
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 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{
|
|
result.Get(0), // avg response
|
|
result.Get(2), // min response
|
|
result.Get(4), // max response
|
|
result.Get(6), // packet loss
|
|
}
|
|
}
|