Add per-node ping monitoring with unreachable error tracking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-25 18:56:12 -08:00
parent a94f816f3d
commit c8be46b739
4 changed files with 172 additions and 17 deletions

View File

@@ -9,8 +9,9 @@ import (
type PortErrorType string
const (
ErrorTypeStartup PortErrorType = "startup"
ErrorTypeNew PortErrorType = "new"
ErrorTypeStartup PortErrorType = "startup"
ErrorTypeNew PortErrorType = "new"
ErrorTypeUnreachable PortErrorType = "unreachable"
)
type PortError struct {
@@ -181,3 +182,52 @@ func (e *ErrorTracker) GetErrors() []*PortError {
}
return errors
}
func (e *ErrorTracker) SetUnreachable(node *Node, ip string) {
changed := e.setUnreachableLocked(node, ip)
if changed {
e.t.NotifyUpdate()
}
}
func (e *ErrorTracker) setUnreachableLocked(node *Node, ip string) bool {
e.mu.Lock()
defer e.mu.Unlock()
key := "unreachable:" + node.TypeID + ":" + ip
if _, exists := e.errors[key]; exists {
return false
}
now := time.Now()
e.nextID++
e.errors[key] = &PortError{
ID: fmt.Sprintf("err-%d", e.nextID),
NodeTypeID: node.TypeID,
NodeName: node.DisplayName(),
PortName: ip,
ErrorType: ErrorTypeUnreachable,
FirstSeen: now,
LastUpdated: now,
}
return true
}
func (e *ErrorTracker) ClearUnreachable(node *Node, ip string) {
changed := e.clearUnreachableLocked(node, ip)
if changed {
e.t.NotifyUpdate()
}
}
func (e *ErrorTracker) clearUnreachableLocked(node *Node, ip string) bool {
e.mu.Lock()
defer e.mu.Unlock()
key := "unreachable:" + node.TypeID + ":" + ip
if _, exists := e.errors[key]; exists {
delete(e.errors, key)
return true
}
return false
}