diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index cb1328a79..4ac947d81 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -174,7 +174,8 @@ void CompatComponent::StatusTimerHandler(void) << "\t" << "check_host_freshness=0" << endl << "\t" << "enable_flap_detection=1" << endl << "\t" << "enable_failure_prediction=0" << endl - << "\t" << "active_scheduled_service_check_stats=" << CheckTask::GetTaskStatistics(60) << "," << CheckTask::GetTaskStatistics(5 * 60) << "," << CheckTask::GetTaskStatistics(15 * 60) << endl + << "\t" << "active_scheduled_service_check_stats=" << CIB::GetTaskStatistics(60) << "," << CIB::GetTaskStatistics(5 * 60) << "," << CIB::GetTaskStatistics(15 * 60) << endl + << "\t" << "}" << endl << endl; ofstream objectfp; diff --git a/icinga/checkresult.cpp b/icinga/checkresult.cpp index 30e866446..dd365687a 100644 --- a/icinga/checkresult.cpp +++ b/icinga/checkresult.cpp @@ -2,99 +2,86 @@ using namespace icinga; -CheckResult::CheckResult(void) - : m_Data(boost::make_shared()) -{ } - -CheckResult::CheckResult(const Dictionary::Ptr& dictionary) - : m_Data(dictionary) -{ } - -Dictionary::Ptr CheckResult::GetDictionary(void) const -{ - return m_Data; -} - void CheckResult::SetScheduleStart(time_t ts) { - m_Data->SetProperty("schedule_start", static_cast(ts)); + SetProperty("schedule_start", static_cast(ts)); } time_t CheckResult::GetScheduleStart(void) const { long value = 0; - m_Data->GetProperty("schedule_start", &value); + GetProperty("schedule_start", &value); return static_cast(value); } void CheckResult::SetScheduleEnd(time_t ts) { - m_Data->SetProperty("schedule_end", static_cast(ts)); + SetProperty("schedule_end", static_cast(ts)); } time_t CheckResult::GetScheduleEnd(void) const { long value = 0; - m_Data->GetProperty("schedule_end", &value); + GetProperty("schedule_end", &value); return static_cast(value); } void CheckResult::SetExecutionStart(time_t ts) { - m_Data->SetProperty("execution_start", static_cast(ts)); + SetProperty("execution_start", static_cast(ts)); } time_t CheckResult::GetExecutionStart(void) const { long value = 0; - m_Data->GetProperty("execution_start", &value); + GetProperty("execution_start", &value); return static_cast(value); } void CheckResult::SetExecutionEnd(time_t ts) { - m_Data->SetProperty("execution_end", static_cast(ts)); + SetProperty("execution_end", static_cast(ts)); } time_t CheckResult::GetExecutionEnd(void) const { long value = 0; - m_Data->GetProperty("execution_end", &value); + GetProperty("execution_end", &value); return value; } void CheckResult::SetState(ServiceState state) { - m_Data->SetProperty("state", static_cast(state)); + SetProperty("state", static_cast(state)); } ServiceState CheckResult::GetState(void) const { long value = StateUnknown; - m_Data->GetProperty("state", &value); + GetProperty("state", &value); return static_cast(value); } void CheckResult::SetOutput(string output) { - m_Data->SetProperty("output", output); + SetProperty("output", output); } string CheckResult::GetOutput(void) const { string value; - m_Data->GetProperty("output", &value); + GetProperty("output", &value); return value; } void CheckResult::SetPerformanceData(const Dictionary::Ptr& pd) { - m_Data->SetProperty("performance_data", pd); + SetProperty("performance_data", pd); } Dictionary::Ptr CheckResult::GetPerformanceData(void) const { Dictionary::Ptr value; - m_Data->GetProperty("performance_data", &value); + GetProperty("performance_data", &value); return value; } diff --git a/icinga/checkresult.h b/icinga/checkresult.h index 7093a497a..049e01cdf 100644 --- a/icinga/checkresult.h +++ b/icinga/checkresult.h @@ -4,13 +4,11 @@ namespace icinga { -struct CheckResult +class CheckResult : public MessagePart { public: - CheckResult(void); - CheckResult(const Dictionary::Ptr& dictionary); - - Dictionary::Ptr GetDictionary(void) const; + CheckResult(void) : MessagePart() { } + CheckResult(const MessagePart& message) : MessagePart(message) { } void SetScheduleStart(time_t ts); time_t GetScheduleStart(void) const; @@ -32,9 +30,6 @@ public: void SetPerformanceData(const Dictionary::Ptr& pd); Dictionary::Ptr GetPerformanceData(void) const; - -private: - Dictionary::Ptr m_Data; }; } diff --git a/icinga/checktask.cpp b/icinga/checktask.cpp index be78472ac..1799b0490 100644 --- a/icinga/checktask.cpp +++ b/icinga/checktask.cpp @@ -5,7 +5,6 @@ using namespace icinga; map CheckTask::m_Types; vector CheckTask::m_FinishedTasks; mutex CheckTask::m_FinishedTasksMutex; -Ringbuffer CheckTask::m_TaskStatistics(15 * 60); CheckTask::CheckTask(const Service& service) : m_Service(service) @@ -68,11 +67,5 @@ void CheckTask::FinishTask(const CheckTask::Ptr& task) { mutex::scoped_lock lock(m_FinishedTasksMutex); m_FinishedTasks.push_back(task); - m_TaskStatistics.InsertValue(task->GetResult().GetScheduleEnd(), 1); } -int CheckTask::GetTaskStatistics(time_t timespan) -{ - mutex::scoped_lock lock(m_FinishedTasksMutex); - return m_TaskStatistics.GetValues(timespan); -} diff --git a/icinga/checktask.h b/icinga/checktask.h index e3a6799a8..c05d3bdc8 100644 --- a/icinga/checktask.h +++ b/icinga/checktask.h @@ -29,8 +29,6 @@ public: static void FinishTask(const CheckTask::Ptr& task); static vector GetFinishedTasks(void); - static int GetTaskStatistics(time_t timespan); - protected: CheckTask(const Service& service); @@ -42,7 +40,6 @@ private: static vector m_FinishedTasks; static mutex m_FinishedTasksMutex; - static Ringbuffer m_TaskStatistics; }; struct CheckTaskType diff --git a/icinga/cib.cpp b/icinga/cib.cpp index 52fb845c2..8c2084234 100644 --- a/icinga/cib.cpp +++ b/icinga/cib.cpp @@ -4,6 +4,7 @@ using namespace icinga; int CIB::m_Types; VirtualEndpoint::Ptr CIB::m_Endpoint; +Ringbuffer CIB::m_TaskStatistics(15 * 60); void CIB::RequireInformation(InformationType types) { @@ -63,5 +64,13 @@ void CIB::ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const Request Dictionary::Ptr cr; if (params.GetProperty("result", &cr)) service.SetLastCheckResult(cr); + + time_t now; + time(&now); + m_TaskStatistics.InsertValue(now, 1); } +int CIB::GetTaskStatistics(long timespan) +{ + return m_TaskStatistics.GetValues(timespan); +} diff --git a/icinga/cib.h b/icinga/cib.h index ab8389ac7..c01a3f389 100644 --- a/icinga/cib.h +++ b/icinga/cib.h @@ -18,10 +18,14 @@ public: static void Start(void); + static int GetTaskStatistics(long timespan); + private: static int m_Types; static VirtualEndpoint::Ptr m_Endpoint; + static Ringbuffer m_TaskStatistics; + static void ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request); }; diff --git a/jsonrpc/jsonrpcclient.cpp b/jsonrpc/jsonrpcclient.cpp index 6f6ab2d3b..091bc884a 100644 --- a/jsonrpc/jsonrpcclient.cpp +++ b/jsonrpc/jsonrpcclient.cpp @@ -51,26 +51,21 @@ void JsonRpcClient::SendMessage(const MessagePart& message) void JsonRpcClient::DataAvailableHandler(void) { for (;;) { + string jsonString; + MessagePart message; + + { + mutex::scoped_lock lock(GetMutex()); + + if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString)) + return; + } + try { - string jsonString; - MessagePart message; - - { - mutex::scoped_lock lock(GetMutex()); - - if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString)) - return; - } - - std::cerr << jsonString << std::endl; - message = MessagePart(jsonString); OnNewMessage(GetSelf(), message); } catch (const std::exception& ex) { Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what())); - Close(); - - return; } } }