Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions internal/monitoring/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package monitoring

import (
"context"
"crypto/rand"
"fmt"
"math/big"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -51,8 +53,22 @@ func StartPinger(ctx context.Context, wg *sync.WaitGroup, device state.Device, i
pingOp = performPing
}

// Initialize timer for first ping with 1 second delay to avoid immediate ping storm
timer := time.NewTimer(1 * time.Second)
// Initialize timer for first ping with jitter to avoid immediate ping storm
// Jitter is random between 0 and interval to spread out initial bursts
initialDelay := 1 * time.Second
if interval > 0 {
val, err := rand.Int(rand.Reader, big.NewInt(int64(interval)))
if err == nil {
initialDelay = time.Duration(val.Int64())
} else {
log.Warn().
Str("ip", device.IP).
Err(err).
Msg("Failed to generate random initial delay, using default 1s fallback")
}
}

timer := time.NewTimer(initialDelay)
defer timer.Stop()

for {
Expand Down
Loading