Metrics: Export last_try_time and last_seen_time of burst observatory.

pull/5132/head
nobody 2025-09-12 12:02:43 +08:00
parent 83c5370eec
commit ef5e0e7ec3
2 changed files with 27 additions and 16 deletions

View File

@ -36,21 +36,23 @@ func (o *Observer) createResult() []*observatory.OutboundStatus {
var result []*observatory.OutboundStatus
o.hp.access.Lock()
defer o.hp.access.Unlock()
for name, value := range o.hp.Results {
curStat := value.getStatistics()
status := observatory.OutboundStatus{
Alive: value.getStatistics().All != value.getStatistics().Fail,
Delay: value.getStatistics().Average.Milliseconds(),
Alive: curStat.All != curStat.Fail,
Delay: curStat.Average.Milliseconds(),
LastErrorReason: "",
OutboundTag: name,
LastSeenTime: 0,
LastTryTime: 0,
LastSeenTime: curStat.LastSeenTime,
LastTryTime: curStat.LastTryTime,
HealthPing: &observatory.HealthPingMeasurementResult{
All: int64(value.getStatistics().All),
Fail: int64(value.getStatistics().Fail),
Deviation: int64(value.getStatistics().Deviation),
Average: int64(value.getStatistics().Average),
Max: int64(value.getStatistics().Max),
Min: int64(value.getStatistics().Min),
All: int64(curStat.All),
Fail: int64(curStat.Fail),
Deviation: int64(curStat.Deviation),
Average: int64(curStat.Average),
Max: int64(curStat.Max),
Min: int64(curStat.Min),
},
}
result = append(result, &status)

View File

@ -7,12 +7,14 @@ import (
// HealthPingStats is the statistics of HealthPingRTTS
type HealthPingStats struct {
All int
Fail int
Deviation time.Duration
Average time.Duration
Max time.Duration
Min time.Duration
All int
Fail int
Deviation time.Duration
Average time.Duration
Max time.Duration
Min time.Duration
LastSeenTime int64
LastTryTime int64
}
// HealthPingRTTS holds ping rtts for health Checker
@ -87,6 +89,10 @@ func (h *HealthPingRTTS) getStatistics() *HealthPingStats {
cnt := 0
validRTTs := make([]time.Duration, 0)
for _, rtt := range h.rtts {
timestamp := rtt.time.Unix()
if timestamp > stats.LastTryTime {
stats.LastTryTime = timestamp
}
switch {
case rtt.value == 0 || time.Since(rtt.time) > h.validity:
continue
@ -94,6 +100,9 @@ func (h *HealthPingRTTS) getStatistics() *HealthPingStats {
stats.Fail++
continue
}
if timestamp > stats.LastSeenTime {
stats.LastSeenTime = timestamp
}
cnt++
sum += rtt.value
validRTTs = append(validRTTs, rtt.value)