From 6f92a629534b030b5822dd9c39a4142f2434ad4e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 13 Dec 2013 15:09:17 +0100 Subject: [PATCH] Implement latency statistics for the "icinga" check. Fixes #5325 --- lib/methods/icingachecktask.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 0744ddde9..8474166a7 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -19,9 +19,11 @@ #include "methods/icingachecktask.h" #include "icinga/cib.h" +#include "icinga/service.h" #include "base/application.h" #include "base/utility.h" #include "base/scriptfunction.h" +#include "base/dynamictype.h" using namespace icinga; @@ -38,6 +40,26 @@ CheckResult::Ptr IcingaCheckTask::ScriptFunc(const Service::Ptr&) perfdata->Set("active_checks", CIB::GetActiveChecksStatistics(interval) / interval); perfdata->Set("passive_checks", CIB::GetPassiveChecksStatistics(interval) / interval); + double min_latency = -1, max_latency = 0, sum_latency = 0; + int count_latency = 0; + + BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { + double latency = Service::CalculateLatency(service->GetLastCheckResult()); + + if (min_latency == -1 || latency < min_latency) + min_latency = latency; + + if (latency > max_latency) + max_latency = latency; + + sum_latency += latency; + count_latency++; + } + + perfdata->Set("min_latency", min_latency); + perfdata->Set("max_latency", max_latency); + perfdata->Set("avg_latency", sum_latency / count_latency); + CheckResult::Ptr cr = make_shared(); cr->SetOutput("Icinga 2 is running."); cr->SetPerformanceData(perfdata);