Fix wrong log lag in cluster-zone check

Refactor the calculation into a generic function.

fixes #8805
This commit is contained in:
Michael Friedrich 2015-09-25 14:23:42 +02:00
parent 251cbbe699
commit c3a47443af
3 changed files with 22 additions and 8 deletions

View File

@ -81,28 +81,28 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
} }
bool connected = false; bool connected = false;
double lag = 0; double zoneLag = 0;
BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) { BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) {
double eplag = Utility::GetTime() - endpoint->GetRemoteLogPosition();
if (endpoint->IsConnected()) if (endpoint->IsConnected())
connected = true; connected = true;
if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && eplag > lag) double eplag = ApiListener::CalculateZoneLag(endpoint);
lag = eplag;
if (eplag > 0 && eplag > zoneLag)
zoneLag = eplag;
} }
if (!connected) { if (!connected) {
cr->SetState(ServiceCritical); 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 { } else {
cr->SetState(ServiceOK); 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(); Array::Ptr perfdata = new Array();
perfdata->Add(new PerfdataValue("slave_lag", lag)); perfdata->Add(new PerfdataValue("slave_lag", zoneLag));
cr->SetPerformanceData(perfdata); cr->SetPerformanceData(perfdata);
checkable->ProcessCheckResult(cr); checkable->ProcessCheckResult(cr);

View File

@ -836,6 +836,17 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus(void)
return std::make_pair(status, perfdata); 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 ApiClient::Ptr& aclient) void ApiListener::AddAnonymousClient(const ApiClient::Ptr& aclient)
{ {
ObjectLock olock(this); ObjectLock olock(this);

View File

@ -68,9 +68,12 @@ public:
void RemoveAnonymousClient(const ApiClient::Ptr& aclient); void RemoveAnonymousClient(const ApiClient::Ptr& aclient);
std::set<ApiClient::Ptr> GetAnonymousClients(void) const; std::set<ApiClient::Ptr> GetAnonymousClients(void) const;
static double CalculateZoneLag(const Endpoint::Ptr& endpoint);
static Value ConfigUpdateHandler(const MessageOrigin& origin, const Dictionary::Ptr& params); static Value ConfigUpdateHandler(const MessageOrigin& origin, const Dictionary::Ptr& params);
static Value HelloAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params); static Value HelloAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params);
protected: protected:
virtual void OnConfigLoaded(void); virtual void OnConfigLoaded(void);
virtual void OnAllConfigLoaded(void); virtual void OnAllConfigLoaded(void);