]> granicus.if.org Git - icinga2/commitdiff
Fix wrong log lag in cluster-zone check
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 25 Sep 2015 12:23:42 +0000 (14:23 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 25 Sep 2015 12:24:45 +0000 (14:24 +0200)
Refactor the calculation into a generic function
which is also used inside the 2.4 status API.

fixes #8805

lib/methods/clusterzonechecktask.cpp
lib/remote/apilistener.cpp
lib/remote/apilistener.hpp

index 8cd788ad1595f97230cb6654119df41c2b6ead28..38c8a718df4821c1d30570699b5cd8a973bead1d 100644 (file)
@@ -81,28 +81,28 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
        }
 
        bool connected = false;
-       double lag = 0;
+       double zoneLag = 0;
 
        BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) {
-               double eplag = Utility::GetTime() - endpoint->GetRemoteLogPosition();
-
                if (endpoint->IsConnected())
                        connected = true;
 
-               if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && eplag > lag)
-                       lag = eplag;
+               double eplag = ApiListener::CalculateZoneLag(endpoint);
+
+               if (eplag > 0 && eplag > zoneLag)
+                       zoneLag = eplag;
        }
 
        if (!connected) {
                cr->SetState(ServiceCritical);
-               cr->SetOutput("Zone '" + zoneName + "' is not connected. Log lag: " + Utility::FormatDuration(lag));
+               cr->SetOutput("Zone '" + zoneName + "' is not connected. Log lag: " + Utility::FormatDuration(zoneLag));
        } else {
                cr->SetState(ServiceOK);
-               cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(lag));
+               cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(zoneLag));
        }
 
        Array::Ptr perfdata = new Array();
-       perfdata->Add(new PerfdataValue("slave_lag", lag));
+       perfdata->Add(new PerfdataValue("slave_lag", zoneLag));
        cr->SetPerformanceData(perfdata);
 
        checkable->ProcessCheckResult(cr);
index c2914d013b1b4d842447abd9c1ef2d39eb119d71..c4422108f8e27038aa15787849b2cbea939eeac5 100644 (file)
@@ -895,9 +895,9 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus(void)
                        if (endpoint->GetName() == GetIdentity())
                                continue;
 
-                       double eplag = Utility::GetTime() - endpoint->GetRemoteLogPosition();
+                       double eplag = CalculateZoneLag(endpoint);
 
-                       if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && eplag > zoneLag)
+                       if (eplag > 0 && eplag > zoneLag)
                                zoneLag = eplag;
 
                        allEndpoints++;
@@ -945,6 +945,17 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus(void)
        return std::make_pair(status, perfdata);
 }
 
+double ApiListener::CalculateZoneLag(const Endpoint::Ptr& endpoint)
+{
+       double remoteLogPosition = endpoint->GetRemoteLogPosition();
+       double eplag = Utility::GetTime() - remoteLogPosition;
+
+       if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && remoteLogPosition != 0)
+               return eplag;
+
+       return 0;
+}
+
 void ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient)
 {
        ObjectLock olock(this);
index 786714b5aa7c3702279cb84e5effe29683984164..203cdadc5181640bd31943bf8c378cb13b9758d4 100644 (file)
@@ -75,6 +75,8 @@ public:
        void RemoveHttpClient(const HttpServerConnection::Ptr& aclient);
        std::set<HttpServerConnection::Ptr> GetHttpClients(void) const;
 
+       static double CalculateZoneLag(const Endpoint::Ptr& endpoint);
+
        /* filesync */
        static Value ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);