From bd1e8b2395a0c23559c8ed4952c5cdc241bbfc9c Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 18 Jun 2012 02:03:24 +0200 Subject: [PATCH] Evenly distribute checks in the check interval. --- base/timer.cpp | 1 - components/checker/checkercomponent.cpp | 1 - components/checker/checkercomponent.h | 2 +- icinga/service.cpp | 14 ++++++++++++-- icinga/service.h | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/base/timer.cpp b/base/timer.cpp index 58e9da42c..33f59f9f1 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -71,7 +71,6 @@ void Timer::RescheduleTimers(void) void Timer::CallExpiredTimers(void) { time_t now; - time(&now); Timer::CollectionType::iterator prev, i; diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index e82792a6d..c6aea671f 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -121,7 +121,6 @@ void CheckerComponent::AdjustCheckTimer(void) /* adjust next call time for the check timer */ Service service = m_Services.top(); - m_CheckTimer->Reschedule(service.GetNextCheck()); } diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index e33402eb1..f39f1b46b 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -26,7 +26,7 @@ namespace icinga struct ServiceNextCheckLessComparer { public: - bool operator()(const Service& a, const Service& b) + bool operator()(Service& a, Service& b) { return a.GetNextCheck() > b.GetNextCheck(); } diff --git a/icinga/service.cpp b/icinga/service.cpp index 31405cfae..8e1394ce1 100644 --- a/icinga/service.cpp +++ b/icinga/service.cpp @@ -53,6 +53,10 @@ long Service::GetCheckInterval(void) const { long value = 300; GetConfigObject()->GetProperty("check_interval", &value); + + if (value < 15) + value = 15; + return value; } @@ -68,10 +72,16 @@ void Service::SetNextCheck(time_t nextCheck) GetConfigObject()->SetTag("next_check", static_cast(nextCheck)); } -time_t Service::GetNextCheck(void) const +time_t Service::GetNextCheck(void) { - long value = 0; + long value = -1; GetConfigObject()->GetTag("next_check", &value); + + if (value == -1) { + value = time(NULL) + rand() % GetCheckInterval(); + SetNextCheck(value); + } + return value; } diff --git a/icinga/service.h b/icinga/service.h index 06dff6641..04f583788 100644 --- a/icinga/service.h +++ b/icinga/service.h @@ -21,7 +21,7 @@ public: long GetRetryInterval(void) const; void SetNextCheck(time_t nextCheck); - time_t GetNextCheck(void) const; + time_t GetNextCheck(void); void SetChecker(string checker); string GetChecker(void) const; void SetPendingCheck(bool pending);