From: Gunnar Beutner Date: Mon, 28 Jan 2013 08:01:47 +0000 (+0100) Subject: Implement statistics for passive service checks. X-Git-Tag: v0.0.2~640 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e78899347973f338a74d2b1b3b3537e7a70c0e6;p=icinga2 Implement statistics for passive service checks. --- diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 11187dacc..5ce26b264 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -322,7 +322,8 @@ void CompatComponent::StatusTimerHandler(void) << "\t" << "check_host_freshness=0" << "\n" << "\t" << "enable_flap_detection=1" << "\n" << "\t" << "enable_failure_prediction=0" << "\n" - << "\t" << "active_scheduled_service_check_stats=" << CIB::GetTaskStatistics(60) << "," << CIB::GetTaskStatistics(5 * 60) << "," << CIB::GetTaskStatistics(15 * 60) << "\n" + << "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\n" + << "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n" << "\t" << "}" << "\n" << "\n"; diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index ef2c71767..a8a50b4af 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -71,8 +71,23 @@ void ReplicationComponent::ServiceStateChangeRequestHandler(const RequestMessage //Service::OnCheckResultReceived(service, params); //service->ApplyCheckResult(cr); - time_t now = static_cast(Utility::GetTime()); - CIB::UpdateTaskStatistics(now, 1); + Dictionary::Ptr cr = service->GetLastCheckResult(); + if (cr) { + Value active = cr->Get("active"); + + time_t ts; + Value schedule_end = cr->Get("schedule_end"); + + if (!schedule_end.IsEmpty()) + schedule_end = static_cast(schedule_end); + else + schedule_end = static_cast(Utility::GetTime()); + + if (active.IsEmpty() || static_cast(active)) + CIB::UpdateActiveChecksStatistics(ts, 1); + else + CIB::UpdatePassiveChecksStatistics(ts, 1); + } } void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint) diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 8be09c20b..a7803eeea 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -452,6 +452,12 @@ void DynamicObject::FinishTx(void) m_CurrentTx = 0; } +void DynamicObject::FlushTx(void) +{ + FinishTx(); + BeginTx(); +} + void DynamicObject::OnAttributeChanged(const String&, const Value&) { } diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index c06973e2b..88973cf3c 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -140,6 +140,7 @@ public: static double GetCurrentTx(void); static void BeginTx(void); static void FinishTx(void); + static void FlushTx(void); protected: virtual void OnAttributeChanged(const String& name, const Value& oldValue); diff --git a/lib/icinga/cib.cpp b/lib/icinga/cib.cpp index d9b7e9353..6502786f6 100644 --- a/lib/icinga/cib.cpp +++ b/lib/icinga/cib.cpp @@ -21,14 +21,25 @@ using namespace icinga; -RingBuffer CIB::m_TaskStatistics(15 * 60); +RingBuffer CIB::m_ActiveChecksStatistics(15 * 60); +RingBuffer CIB::m_PassiveChecksStatistics(15 * 60); -void CIB::UpdateTaskStatistics(long tv, int num) +void CIB::UpdateActiveChecksStatistics(long tv, int num) { - m_TaskStatistics.InsertValue(tv, num); + m_ActiveChecksStatistics.InsertValue(tv, num); } -int CIB::GetTaskStatistics(long timespan) +int CIB::GetActiveChecksStatistics(long timespan) { - return m_TaskStatistics.GetValues(timespan); + return m_ActiveChecksStatistics.GetValues(timespan); +} + +void CIB::UpdatePassiveChecksStatistics(long tv, int num) +{ + m_PassiveChecksStatistics.InsertValue(tv, num); +} + +int CIB::GetPassiveChecksStatistics(long timespan) +{ + return m_PassiveChecksStatistics.GetValues(timespan); } diff --git a/lib/icinga/cib.h b/lib/icinga/cib.h index fc4bc5392..a9eaa907c 100644 --- a/lib/icinga/cib.h +++ b/lib/icinga/cib.h @@ -32,11 +32,15 @@ namespace icinga class I2_ICINGA_API CIB { public: - static void UpdateTaskStatistics(long tv, int num); - static int GetTaskStatistics(long timespan); + static void UpdateActiveChecksStatistics(long tv, int num); + static int GetActiveChecksStatistics(long timespan); + + static void UpdatePassiveChecksStatistics(long tv, int num); + static int GetPassiveChecksStatistics(long timespan); private: - static RingBuffer m_TaskStatistics; + static RingBuffer m_ActiveChecksStatistics; + static RingBuffer m_PassiveChecksStatistics; }; } diff --git a/lib/icinga/externalcommand.cpp b/lib/icinga/externalcommand.cpp index 92db8a0a3..e72e6ad85 100644 --- a/lib/icinga/externalcommand.cpp +++ b/lib/icinga/externalcommand.cpp @@ -130,6 +130,7 @@ void ExternalCommand::ProcessServiceCheckResult(double time, const vectorSet("schedule_end", time); result->Set("execution_start", time); result->Set("execution_end", time); + result->Set("active", 0); Logger::Write(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'"); service->ProcessCheckResult(result); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 5bd1d3650..5104d2696 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -678,6 +678,9 @@ void Service::CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo, if (!result->Contains("execution_end")) result->Set("execution_end", scheduleInfo->Get("execution_end")); + if (!result->Contains("active")) + result->Set("active", 1); + ProcessCheckResult(result); } } catch (const exception& ex) { @@ -699,6 +702,10 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) { ApplyCheckResult(cr); + /* flush the current transaction so other instances see the service's + * new state when they receive the ServiceStateChange message */ + DynamicObject::FlushTx(); + RequestMessage rm; rm.SetMethod("checker::ServiceStateChange");