Skip to content

Commit

Permalink
Add periodic info logging of scheduled checks (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg committed Mar 30, 2017
1 parent a0cfcaf commit b0f8e89
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion poller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

const (
checkPreparationBufferSize = 10
checkLoggerDuration = 5 * time.Minute
)

// EleScheduler implements Scheduler interface.
Expand Down Expand Up @@ -112,14 +113,36 @@ func (s *EleScheduler) ReconcileChecks(cp ChecksPrepared) {
}

func (s *EleScheduler) runReconciler() {

logTicker := time.NewTicker(checkLoggerDuration)
defer logTicker.Stop()

for {
select {
case cp := <-s.preparations:
s.reconcile(cp)
s.logScheduledChecks()

case <-s.ctx.Done():
return

case <-logTicker.C:
s.logScheduledChecks()
}
}
}

func (s *EleScheduler) logScheduledChecks() {
if len(s.checks) > 0 {
typeCounts := log.Fields{}
for _, ch := range s.checks {
count, _ := typeCounts[ch.GetCheckType()].(int)
count++
typeCounts[ch.GetCheckType()] = count
}
log.WithFields(typeCounts).Info("Checks scheduled to run")
} else {
log.Info("No checks are scheduled to run")
}
}

Expand Down Expand Up @@ -237,7 +260,7 @@ func (s *EleScheduler) runCheckTimerLoop(ch check.Check) {
"checkId": ch.GetID(),
"jitterMs": jitter,
"waitPeriod": ch.GetWaitPeriod(),
}).Info("Starting check")
}).Debug("Starting check")

time.Sleep(time.Duration(jitter) * time.Millisecond)
for {
Expand All @@ -254,6 +277,12 @@ func (s *EleScheduler) runCheckTimerLoop(ch check.Check) {

// Execute perform the default CheckExecutor behavior by running the check and sending its results via SendMetrics.
func (s *EleScheduler) Execute(ch check.Check) {
log.WithFields(log.Fields{
"id": ch.GetID(),
"type": ch.GetCheckType(),
"period": ch.GetPeriod(),
}).Debug("Running check")

crs, err := ch.Run()
if err != nil {
log.Errorf("Error running check: %v", err)
Expand Down

0 comments on commit b0f8e89

Please sign in to comment.