Documentation
¶
Overview ¶
Package stats provides shared statistics tracking for nodes.
Index ¶
- type DirtyFlags
- type SharedStats
- func (s *SharedStats) AvgRTT() time.Duration
- func (s *SharedStats) FailureCount() int
- func (s *SharedStats) FirstSeen() time.Time
- func (s *SharedStats) GetSnapshot() Snapshot
- func (s *SharedStats) IncrementFailureCount()
- func (s *SharedStats) IncrementSuccessCount()
- func (s *SharedStats) IsAlive(maxAge time.Duration, maxFailures int) bool
- func (s *SharedStats) LastPing() time.Time
- func (s *SharedStats) LastSeen() time.Time
- func (s *SharedStats) NeedsPing(pingInterval time.Duration) bool
- func (s *SharedStats) ResetFailureCount()
- func (s *SharedStats) SetCallback(callback func(DirtyFlags))
- func (s *SharedStats) SetFailureCount(count int)
- func (s *SharedStats) SetFirstSeen(t time.Time)
- func (s *SharedStats) SetLastPing(t time.Time)
- func (s *SharedStats) SetLastSeen(t time.Time)
- func (s *SharedStats) SetSuccessCount(count int)
- func (s *SharedStats) SuccessCount() int
- func (s *SharedStats) UpdateRTT(rtt time.Duration)
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DirtyFlags ¶
type DirtyFlags uint8
DirtyFlags represents which stats fields were updated.
const ( DirtyLastSeen DirtyFlags = 0x01 // last_seen updated DirtyStats DirtyFlags = 0x02 // success/failure/rtt updated )
type SharedStats ¶
type SharedStats struct {
// contains filtered or unexported fields
}
SharedStats holds node statistics that can be shared between protocol-specific nodes (v4/v5) and the generic node wrapper. It includes its own mutex for thread-safe access.
func NewSharedStats ¶
func NewSharedStats(firstSeen time.Time) *SharedStats
NewSharedStats creates a new SharedStats with the given first seen time.
func (*SharedStats) AvgRTT ¶
func (s *SharedStats) AvgRTT() time.Duration
AvgRTT returns the average round-trip time.
func (*SharedStats) FailureCount ¶
func (s *SharedStats) FailureCount() int
FailureCount returns the consecutive failure count.
func (*SharedStats) FirstSeen ¶
func (s *SharedStats) FirstSeen() time.Time
FirstSeen returns the first time the node was discovered.
func (*SharedStats) GetSnapshot ¶
func (s *SharedStats) GetSnapshot() Snapshot
GetSnapshot returns a snapshot of the current statistics.
func (*SharedStats) IncrementFailureCount ¶
func (s *SharedStats) IncrementFailureCount()
IncrementFailureCount increases the failure count by 1.
func (*SharedStats) IncrementSuccessCount ¶
func (s *SharedStats) IncrementSuccessCount()
IncrementSuccessCount increases the success count by 1.
func (*SharedStats) IsAlive ¶
func (s *SharedStats) IsAlive(maxAge time.Duration, maxFailures int) bool
IsAlive checks if the node is considered alive. A node is alive if it was seen recently and has few failures.
func (*SharedStats) LastPing ¶
func (s *SharedStats) LastPing() time.Time
LastPing returns the last time a ping was sent to the node.
func (*SharedStats) LastSeen ¶
func (s *SharedStats) LastSeen() time.Time
LastSeen returns the last time the node was seen.
func (*SharedStats) NeedsPing ¶
func (s *SharedStats) NeedsPing(pingInterval time.Duration) bool
NeedsPing checks if the node needs a liveness check. Returns true if never pinged or it's been longer than pingInterval.
func (*SharedStats) ResetFailureCount ¶
func (s *SharedStats) ResetFailureCount()
ResetFailureCount resets the failure count to 0 and increments success count.
func (*SharedStats) SetCallback ¶
func (s *SharedStats) SetCallback(callback func(DirtyFlags))
SetCallback sets the callback function that is triggered when stats are updated. The callback receives dirty flags indicating which fields were changed. This is typically used to notify the database to persist changes.
func (*SharedStats) SetFailureCount ¶
func (s *SharedStats) SetFailureCount(count int)
SetFailureCount sets the failure count.
func (*SharedStats) SetFirstSeen ¶
func (s *SharedStats) SetFirstSeen(t time.Time)
SetFirstSeen updates the first seen time.
func (*SharedStats) SetLastPing ¶
func (s *SharedStats) SetLastPing(t time.Time)
SetLastPing updates the last ping time.
func (*SharedStats) SetLastSeen ¶
func (s *SharedStats) SetLastSeen(t time.Time)
SetLastSeen updates the last seen time.
func (*SharedStats) SetSuccessCount ¶
func (s *SharedStats) SetSuccessCount(count int)
SetSuccessCount sets the success count.
func (*SharedStats) SuccessCount ¶
func (s *SharedStats) SuccessCount() int
SuccessCount returns the total success count.
func (*SharedStats) UpdateRTT ¶
func (s *SharedStats) UpdateRTT(rtt time.Duration)
UpdateRTT updates the average RTT using exponential moving average. The new average is: avgRTT = (0.875 * avgRTT) + (0.125 * newRTT)