]> granicus.if.org Git - icinga2/commitdiff
Implement latency statistics for the "icinga" check.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 13 Dec 2013 14:09:17 +0000 (15:09 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 13 Dec 2013 14:09:17 +0000 (15:09 +0100)
Fixes #5325

lib/methods/icingachecktask.cpp

index 0744ddde93da6474e3b0e75bd3c9a06ececaf97a..8474166a7db2e08e916640de5913864b8e78452a 100644 (file)
 
 #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<Service>()) {
+               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<CheckResult>();
        cr->SetOutput("Icinga 2 is running.");
        cr->SetPerformanceData(perfdata);