******************************************************************************/
#include "icinga/cib.h"
+#include "icinga/service.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
using namespace icinga;
{
return m_PassiveChecksStatistics.GetValues(timespan);
}
+
+ServiceCheckStatistics CIB::CalculateServiceCheckStats(void)
+{
+ double min_latency = -1, max_latency = 0, sum_latency = 0;
+ int count_latency = 0;
+ double min_execution_time = -1, max_execution_time = 0, sum_execution_time = 0;
+ int count_execution_time = 0;
+
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
+ ObjectLock olock(service);
+
+ CheckResult::Ptr cr = service->GetLastCheckResult();
+
+ /* latency */
+ double latency = Service::CalculateLatency(cr);
+
+ if (min_latency == -1 || latency < min_latency)
+ min_latency = latency;
+
+ if (latency > max_latency)
+ max_latency = latency;
+
+ sum_latency += latency;
+ count_latency++;
+
+ /* execution_time */
+ double execution_time = Service::CalculateExecutionTime(cr);
+
+ if (min_execution_time == -1 || execution_time < min_execution_time)
+ min_execution_time = execution_time;
+
+ if (execution_time > max_execution_time)
+ max_execution_time = execution_time;
+
+ sum_execution_time += execution_time;
+ count_execution_time++;
+ }
+
+ ServiceCheckStatistics scs = {0};
+
+ scs.min_latency = min_latency;
+ scs.max_latency = max_latency;
+ scs.avg_latency = sum_latency / count_latency;
+ scs.min_execution_time = min_execution_time;
+ scs.max_execution_time = max_execution_time;
+ scs.avg_execution_time = sum_execution_time / count_execution_time;
+
+ return scs;
+}
+
+ServiceStatistics CIB::CalculateServiceStats(void)
+{
+ ServiceStatistics ss = {0};
+
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
+ ObjectLock olock(service);
+
+ CheckResult::Ptr cr = service->GetLastCheckResult();
+
+ if (service->GetState() == StateOK)
+ ss.services_ok++;
+ if (service->GetState() == StateWarning)
+ ss.services_warning++;
+ if (service->GetState() == StateCritical)
+ ss.services_critical++;
+ if (service->GetState() == StateUnknown)
+ ss.services_unknown++;
+
+ if (!cr)
+ ss.services_pending++;
+ if (!service->IsReachable())
+ ss.services_unreachable++;
+
+ if (service->IsFlapping())
+ ss.services_flapping++;
+ if (service->IsInDowntime())
+ ss.services_in_downtime++;
+ if (service->IsAcknowledged())
+ ss.services_acknowledged++;
+ }
+
+ return ss;
+}
+
+HostStatistics CIB::CalculateHostStats(void)
+{
+ HostStatistics hs = {0};
+
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
+ ObjectLock olock(host);
+
+ if (host->GetState() == HostUp)
+ hs.hosts_up++;
+ if (host->GetState() == HostDown)
+ hs.hosts_down++;
+ if (host->GetState() == HostUnreachable)
+ hs.hosts_unreachable++;
+
+ Service::Ptr hc = host->GetCheckService();
+
+ if (!hc) {
+ hs.hosts_pending++;
+ continue; /* skip host service check counting */
+ }
+
+ if (!hc->GetLastCheckResult())
+ hs.hosts_pending++;
+
+ if (hc->IsFlapping())
+ hs.hosts_flapping++;
+ if (hc->IsInDowntime())
+ hs.hosts_in_downtime++;
+ if (hc->IsAcknowledged())
+ hs.hosts_acknowledged++;
+ }
+
+ return hs;
+}
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;
- double min_execution_time = -1, max_execution_time = 0, sum_execution_time = 0;
- int count_execution_time = 0;
-
- double services_ok, services_warn, services_crit, services_unknown, services_pending, services_unreachable,
- services_flapping, services_in_downtime, services_acknowledged = 0;
- double hosts_up, hosts_down, hosts_unreachable, hosts_pending, hosts_flapping, hosts_in_downtime, hosts_acknowledged = 0;
-
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
- ObjectLock olock(service);
-
- CheckResult::Ptr cr = service->GetLastCheckResult();
-
- /* latency */
- double latency = Service::CalculateLatency(cr);
-
- if (min_latency == -1 || latency < min_latency)
- min_latency = latency;
-
- if (latency > max_latency)
- max_latency = latency;
-
- sum_latency += latency;
- count_latency++;
-
- /* execution_time */
- double execution_time = Service::CalculateExecutionTime(cr);
-
- if (min_execution_time == -1 || execution_time < min_execution_time)
- min_execution_time = execution_time;
-
- if (execution_time > max_execution_time)
- max_execution_time = execution_time;
-
- sum_execution_time += execution_time;
- count_execution_time++;
-
- /* states */
- if (service->GetState() == StateOK)
- services_ok++;
- if (service->GetState() == StateWarning)
- services_warn++;
- if (service->GetState() == StateCritical)
- services_crit++;
- if (service->GetState() == StateUnknown)
- services_unknown++;
-
- /* pending, unreachable */
- if (!cr)
- services_pending++;
- if (!service->IsReachable())
- services_unreachable++;
-
- /* flapping, downtime, acknowledgements */
- if (service->IsFlapping())
- services_flapping++;
- if (service->IsInDowntime())
- services_in_downtime++;
- if (service->IsAcknowledged())
- services_acknowledged++;
- }
-
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
- ObjectLock olock(host);
-
- if (host->GetState() == HostUp)
- hosts_up++;
- if (host->GetState() == HostDown)
- hosts_down++;
- if (host->GetState() == HostUnreachable)
- hosts_unreachable++;
-
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- hosts_pending++;
- continue; /* skip host service check counting */
- }
-
- if (!hc->GetLastCheckResult())
- hosts_pending++;
-
- if (hc->IsFlapping())
- hosts_flapping++;
- if (hc->IsInDowntime())
- hosts_in_downtime++;
- if (hc->IsAcknowledged())
- hosts_acknowledged++;
- }
-
- perfdata->Set("min_latency", min_latency);
- perfdata->Set("max_latency", max_latency);
- perfdata->Set("avg_latency", sum_latency / count_latency);
- perfdata->Set("min_execution_time", min_latency);
- perfdata->Set("max_execution_time", max_latency);
- perfdata->Set("avg_execution_time", sum_execution_time / count_execution_time);
-
- perfdata->Set("num_services_ok", services_ok);
- perfdata->Set("num_services_warn", services_warn);
- perfdata->Set("num_services_crit", services_crit);
- perfdata->Set("num_services_unknown", services_unknown);
- perfdata->Set("num_services_pending", services_pending);
- perfdata->Set("num_services_unreachable", services_unreachable);
- perfdata->Set("num_services_flapping", services_flapping);
- perfdata->Set("num_services_in_downtime", services_in_downtime);
- perfdata->Set("num_services_acknowledged", services_acknowledged);
-
- perfdata->Set("num_hosts_up", hosts_up);
- perfdata->Set("num_hosts_down", hosts_down);
- perfdata->Set("num_hosts_unreachable", hosts_unreachable);
- perfdata->Set("num_hosts_flapping", hosts_flapping);
- perfdata->Set("num_hosts_in_downtime", hosts_in_downtime);
- perfdata->Set("num_hosts_acknowledged", hosts_acknowledged);
+ ServiceCheckStatistics scs = CIB::CalculateServiceCheckStats();
+
+ perfdata->Set("min_latency", scs.min_latency);
+ perfdata->Set("max_latency", scs.max_latency);
+ perfdata->Set("avg_latency", scs.avg_latency);
+ perfdata->Set("min_execution_time", scs.min_latency);
+ perfdata->Set("max_execution_time", scs.max_latency);
+ perfdata->Set("avg_execution_time", scs.avg_execution_time);
+
+ ServiceStatistics ss = CIB::CalculateServiceStats();
+
+ perfdata->Set("num_services_ok", ss.services_ok);
+ perfdata->Set("num_services_warning", ss.services_warning);
+ perfdata->Set("num_services_critical", ss.services_critical);
+ perfdata->Set("num_services_unknown", ss.services_unknown);
+ perfdata->Set("num_services_pending", ss.services_pending);
+ perfdata->Set("num_services_unreachable", ss.services_unreachable);
+ perfdata->Set("num_services_flapping", ss.services_flapping);
+ perfdata->Set("num_services_in_downtime", ss.services_in_downtime);
+ perfdata->Set("num_services_acknowledged", ss.services_acknowledged);
+
+ HostStatistics hs = CIB::CalculateHostStats();
+
+ perfdata->Set("num_hosts_up", hs.hosts_up);
+ perfdata->Set("num_hosts_down", hs.hosts_down);
+ perfdata->Set("num_hosts_unreachable", hs.hosts_unreachable);
+ perfdata->Set("num_hosts_flapping", hs.hosts_flapping);
+ perfdata->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
+ perfdata->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
CheckResult::Ptr cr = make_shared<CheckResult>();
cr->SetOutput("Icinga 2 is running.");