]> granicus.if.org Git - icinga2/commitdiff
Try to more uniformly distribute checks in their check interval.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 17 Jul 2012 17:10:14 +0000 (19:10 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 17 Jul 2012 17:10:14 +0000 (19:10 +0200)
cib/service.cpp
components/checker/checkercomponent.cpp

index 6a4d4bc16282864cbed5939399821f2eaa33d216..0a015112db7c1180bcce704c79a7921f8226e36a 100644 (file)
@@ -190,13 +190,18 @@ time_t Service::GetNextCheck(void)
 
 void Service::UpdateNextCheck(void)
 {
-       time_t now;
+       time_t now, previous, next, interval;
+
        time(&now);
+       previous = GetNextCheck();
 
        if (GetStateType() == StateTypeSoft)
-               SetNextCheck(now + GetRetryInterval());
+               interval = GetRetryInterval();
        else
-               SetNextCheck(now + GetCheckInterval());
+               interval = GetCheckInterval();
+
+       next = now + ((now - previous) / interval + 1) * interval;
+       SetNextCheck(next);
 }
 
 void Service::SetChecker(const string& checker)
index 5157ed5df5756223e8f727214c870506fb247c97..d77d063904380938db845d8154f958bce82ebfee 100644 (file)
@@ -104,6 +104,9 @@ void CheckerComponent::CheckCompletedHandler(Service service, const ScriptTask::
 {
        service.RemoveTag("current_task");
 
+       /* figure out when the next check is for this service */
+       service.UpdateNextCheck();
+
        try {
                Variant vresult = task->GetResult();
 
@@ -135,14 +138,13 @@ void CheckerComponent::CheckCompletedHandler(Service service, const ScriptTask::
                Logger::Write(LogWarning, "checker", msgbuf.str());
        }
 
-       /* figure out when the next check is for this service */
-       service.UpdateNextCheck();
-
        /* remove the service from the list of pending services; if it's not in the
         * list this was a manual (i.e. forced) check and we must not re-add the
         * service to the services list because it's already there. */
-       if (m_PendingServices.find(service.GetConfigObject()) != m_PendingServices.end()) {
-               m_PendingServices.erase(service.GetConfigObject());
+       set<ConfigObject::Ptr>::iterator it;
+       it = m_PendingServices.find(service.GetConfigObject());
+       if (it != m_PendingServices.end()) {
+               m_PendingServices.erase(it);
                m_Services.push(service);
        }