Implement latency statistics for the "icinga" check.

Fixes #5325
This commit is contained in:
Gunnar Beutner 2013-12-13 15:09:17 +01:00
parent 0e4c00805c
commit 6f92a62953
1 changed files with 22 additions and 0 deletions

View File

@ -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<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);