Update
This commit is contained in:
parent
d37503c863
commit
1509789cde
19 changed files with 1534 additions and 112 deletions
|
|
@ -77,6 +77,16 @@ type Store struct {
|
|||
persistenceFile string
|
||||
order []string
|
||||
monitors map[string]*MonitorState
|
||||
onRecord func(monitorID string, res CheckResult)
|
||||
}
|
||||
|
||||
// SetOnRecord registers a callback invoked (outside the store lock) after every
|
||||
// successfully recorded check result. It is intended for long-term history
|
||||
// sinks such as the daily log and stats database.
|
||||
func (s *Store) SetOnRecord(fn func(monitorID string, res CheckResult)) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.onRecord = fn
|
||||
}
|
||||
|
||||
// New creates a new Store initialized with the configured monitors.
|
||||
|
|
@ -113,10 +123,10 @@ func New(cfg *config.Config) *Store {
|
|||
// Record appends a new check result for monitorID and recalculates its statistics.
|
||||
func (s *Store) Record(monitorID string, res CheckResult) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
m, ok := s.monitors[monitorID]
|
||||
if !ok {
|
||||
s.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -168,6 +178,13 @@ func (s *Store) Record(monitorID string, res CheckResult) {
|
|||
if latCount > 0 {
|
||||
m.AvgLatencyMs = round2(latSum / float64(latCount))
|
||||
}
|
||||
|
||||
onRecord := s.onRecord
|
||||
s.mu.Unlock()
|
||||
|
||||
if onRecord != nil {
|
||||
onRecord(monitorID, res)
|
||||
}
|
||||
}
|
||||
|
||||
// Snapshot returns a deep copy of current monitor states and aggregate metrics.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue