diff --git a/base/application.cpp b/base/application.cpp index d057d8ec8..ea479cbeb 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -299,6 +299,10 @@ void Application::Log(LogSeverity severity, const string& facility, const string { char timestamp[100]; + // TODO: make this configurable + if (severity < LogInformation) + return; + string severityStr; switch (severity) { case LogDebug: diff --git a/base/threadpool.h b/base/threadpool.h index 7c905b09a..5032a6d2d 100644 --- a/base/threadpool.h +++ b/base/threadpool.h @@ -18,7 +18,7 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - ThreadPool(long numThreads = 128); + ThreadPool(long maxThreads = 128); ~ThreadPool(void); static ThreadPool::Ptr GetDefaultPool(void); diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 2dd515407..212275900 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -76,7 +76,7 @@ void CheckerComponent::CheckTimerHandler(void) m_Services.pop(); -// Application::Log(LogInformation, "checker", "Executing service check for '" + service.GetName() + "'"); + Application::Log(LogDebug, "checker", "Executing service check for '" + service.GetName() + "'"); CheckTask::Ptr task = CheckTask::CreateTask(service); task->Enqueue(); @@ -90,7 +90,7 @@ void CheckerComponent::CheckTimerHandler(void) stringstream msgbuf; msgbuf << "CheckTimerHandler: created " << tasks << " tasks"; - Application::Log(LogDebug, "checker", msgbuf.str()); + Application::Log(LogInformation, "checker", msgbuf.str()); } void CheckerComponent::ResultTimerHandler(void) @@ -100,7 +100,7 @@ void CheckerComponent::ResultTimerHandler(void) time_t now; time(&now); - long min_latency = -1, max_latency = 0, avg_latency = 0, results = 0; + long min_latency = -1, max_latency = 0, avg_latency = 0, results = 0, failed = 0; vector finishedTasks = CheckTask::GetFinishedTasks(); @@ -110,7 +110,7 @@ void CheckerComponent::ResultTimerHandler(void) Service service = task->GetService(); CheckResult result = task->GetResult(); -// Application::Log(LogInformation, "checker", "Got result! Plugin output: " + result.Output); + Application::Log(LogDebug, "checker", "Got result for service '" + service.GetName() + "'"); long latency = result.EndTime - result.StartTime; avg_latency += latency; @@ -123,13 +123,16 @@ void CheckerComponent::ResultTimerHandler(void) results++; + if (result.State != StateOK) + failed++; + service.SetNextCheck(now + service.GetCheckInterval()); m_Services.push(service); } stringstream msgbuf; - msgbuf << "ResultTimerHandler: " << results << " results; latency: avg=" << avg_latency / (results ? results : 1) << ", min=" << min_latency << ", max: " << max_latency; - Application::Log(LogDebug, "checker", msgbuf.str()); + msgbuf << "ResultTimerHandler: " << results << " results (" << failed << " failed); latency: avg=" << avg_latency / (results ? results : 1) << ", min=" << min_latency << ", max: " << max_latency; + Application::Log(LogInformation, "checker", msgbuf.str()); } void CheckerComponent::AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) @@ -146,7 +149,7 @@ void CheckerComponent::AssignServiceRequestHandler(const Endpoint::Ptr& sender, Service service(object); m_Services.push(service); - Application::Log(LogInformation, "checker", "Accepted delegation for service '" + service.GetName() + "'"); + Application::Log(LogDebug, "checker", "Accepted delegation for service '" + service.GetName() + "'"); /* force a service check */ m_CheckTimer->Reschedule(0); @@ -189,7 +192,7 @@ void CheckerComponent::RevokeServiceRequestHandler(const Endpoint::Ptr& sender, for (it = services.begin(); it != services.end(); it++) m_Services.push(*it); - Application::Log(LogInformation, "checker", "Revoked delegation for service '" + name + "'"); + Application::Log(LogDebug, "checker", "Revoked delegation for service '" + name + "'"); string id; if (request.GetID(&id)) { @@ -204,7 +207,7 @@ void CheckerComponent::RevokeServiceRequestHandler(const Endpoint::Ptr& sender, void CheckerComponent::ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) { - Application::Log(LogInformation, "checker", "Clearing service delegations."); + Application::Log(LogDebug, "checker", "Clearing service delegations."); m_Services = ServiceQueue(); string id; diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index f52a48060..ef228e1a9 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -72,7 +72,7 @@ void DelegationComponent::AssignService(const Service& service) params.SetProperty("service", service.GetConfigObject()->GetProperties()); request.SetParams(params); - Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service.GetName() + "'"); + Application::Log(LogDebug, "delegation", "Trying to delegate service '" + service.GetName() + "'"); GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request, boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5)); @@ -81,10 +81,10 @@ void DelegationComponent::AssignService(const Service& service) void DelegationComponent::AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut) { if (timedOut) { - Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' timed out."); + Application::Log(LogDebug, "delegation", "Service delegation for service '" + service.GetName() + "' timed out."); } else { service.SetChecker(sender->GetIdentity()); - Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' was successful."); + Application::Log(LogDebug, "delegation", "Service delegation for service '" + service.GetName() + "' was successful."); } } @@ -100,6 +100,7 @@ void DelegationComponent::RevokeServiceResponseHandler(Service& service, const E void DelegationComponent::DelegationTimerHandler(void) { ConfigObject::Set::Iterator it; + long delegated = 0; for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) { Service service = *it; @@ -108,9 +109,12 @@ void DelegationComponent::DelegationTimerHandler(void) continue; AssignService(service); + delegated++; } - m_DelegationTimer->Stop(); + stringstream msgbuf; + msgbuf << "Delegated " << delegated << " services"; + Application::Log(LogInformation, "delegation", msgbuf.str()); } EXPORT_COMPONENT(delegation, DelegationComponent);