From 232c299a7ad657e4590d8f6367f1bb37269e4555 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 18 May 2016 14:30:36 +0200 Subject: [PATCH] Fix 100% CPU usage issue and incorrect pending checks accounting in CheckerComponent::CheckThreadProc fixes #11806 --- lib/checker/checkercomponent.cpp | 5 ++++- lib/methods/pluginchecktask.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index fb9d87188..bfb997fb6 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -121,7 +121,10 @@ void CheckerComponent::CheckThreadProc(void) double wait = checkable->GetNextCheck() - Utility::GetTime(); - if (wait > 0 || Checkable::GetPendingChecks() >= GetConcurrentChecks()) { + if (Checkable::GetPendingChecks() >= GetConcurrentChecks()) + wait = 0.5; + + if (wait > 0) { /* Wait for the next check. */ m_CV.timed_wait(lock, boost::posix_time::milliseconds(wait * 1000)); diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index c1b1942d9..d53e287f8 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -52,11 +52,12 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.push_back(std::make_pair("command", commandObj)); resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); - Checkable::IncreasePendingChecks(); - PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, resolvedMacros, useResolvedMacros, boost::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2)); + + if (!resolvedMacros || useResolvedMacros) + Checkable::IncreasePendingChecks(); } void PluginCheckTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Value& commandLine, const ProcessResult& pr) -- 2.40.0