bc3a44beac
Propagate check failure reasons through the entire stack: - Checker captures specific errors (DNS, timeout, HTTP status, SSL, etc.) - Engine tracks LastError, StatusChangedAt, LastSuccessAt per monitor - State transitions persisted to new state_changes table - Detail panel shows error reason, HTTP code, state duration, last success time, and last 5 state change events - Monitor table shows inline error preview for DOWN services - Alert messages include error reason - Probe nodes forward error reasons to leader 15 files changed across models, checker, engine, store, TUI, and probes.
46 lines
865 B
Go
46 lines
865 B
Go
package monitor
|
|
|
|
import "time"
|
|
|
|
type AggregationStrategy string
|
|
|
|
const (
|
|
AggAnyDown AggregationStrategy = "any-down"
|
|
AggMajorityDown AggregationStrategy = "majority-down"
|
|
AggAllDown AggregationStrategy = "all-down"
|
|
)
|
|
|
|
type NodeResult struct {
|
|
NodeID string
|
|
IsUp bool
|
|
LatencyNs int64
|
|
CheckedAt time.Time
|
|
ErrorReason string
|
|
}
|
|
|
|
func AggregateStatus(results []NodeResult, strategy AggregationStrategy) (isUp bool, avgLatencyNs int64) {
|
|
if len(results) == 0 {
|
|
return true, 0
|
|
}
|
|
|
|
upCount := 0
|
|
var totalLatency int64
|
|
for _, r := range results {
|
|
if r.IsUp {
|
|
upCount++
|
|
}
|
|
totalLatency += r.LatencyNs
|
|
}
|
|
avgLatencyNs = totalLatency / int64(len(results))
|
|
|
|
switch strategy {
|
|
case AggMajorityDown:
|
|
isUp = upCount > len(results)/2
|
|
case AggAllDown:
|
|
isUp = upCount > 0
|
|
default:
|
|
isUp = upCount == len(results)
|
|
}
|
|
return
|
|
}
|