]> granicus.if.org Git - icinga2/commitdiff
Evenly distribute checks in the check interval.
authorGunnar Beutner <gunnar@beutner.name>
Mon, 18 Jun 2012 00:03:24 +0000 (02:03 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 18 Jun 2012 00:19:15 +0000 (02:19 +0200)
base/timer.cpp
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
icinga/service.cpp
icinga/service.h

index 58e9da42c88820ec75b050badcf3c75690cca328..33f59f9f1241fb391151442c73582b0f95d87ac8 100644 (file)
@@ -71,7 +71,6 @@ void Timer::RescheduleTimers(void)
 void Timer::CallExpiredTimers(void)
 {
        time_t now;
-
        time(&now);
 
        Timer::CollectionType::iterator prev, i;
index e82792a6def7110898306a8e6d97317d78b106d1..c6aea671fa8749dc76a45630467fa5c96753c271 100644 (file)
@@ -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());
 }
 
index e33402eb135a138d4229a60c7cf7f13b8d25186c..f39f1b46bffb33aa8538c496ec5daf1c2c05f0b5 100644 (file)
@@ -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();
        }
index 31405cfaefc786c2ec75aecdbe55af96c91bea54..8e1394ce1f1a456966f7614e6d6a1703bd906ef0 100644 (file)
@@ -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<long>(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;
 }
 
index 06dff6641f7671c2cd8ba907ad079c2ac395c98a..04f583788d45f887007c928d159dc10888885179 100644 (file)
@@ -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);