]> granicus.if.org Git - icinga2/commitdiff
Metrics: Expose problem/handled counts for hosts/services 7459/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 29 Aug 2019 15:04:23 +0000 (17:04 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 29 Aug 2019 15:04:23 +0000 (17:04 +0200)
With the addition of problem/handled as checkable runtime
attributes in #7096 we should also expose them via CIB
into

- icinga check
- /v1/status/CIB
- IcingaApplication runtime macros

This originates from a request by @phil-or at the recent
Icinga meetup in Linz.

lib/icinga/cib.cpp
lib/icinga/cib.hpp
lib/icinga/icingaapplication.cpp
lib/methods/icingachecktask.cpp

index a48b850784942f7c20c2bc7fef6ba94fe83bf654..0cb6ef0d504de22be257a94c7d643fd7a75f5109 100644 (file)
@@ -187,8 +187,6 @@ ServiceStatistics CIB::CalculateServiceStats()
        for (const Service::Ptr& service : ConfigType::GetObjectsByType<Service>()) {
                ObjectLock olock(service);
 
-               CheckResult::Ptr cr = service->GetLastCheckResult();
-
                if (service->GetState() == ServiceOK)
                        ss.services_ok++;
                if (service->GetState() == ServiceWarning)
@@ -198,8 +196,11 @@ ServiceStatistics CIB::CalculateServiceStats()
                if (service->GetState() == ServiceUnknown)
                        ss.services_unknown++;
 
+               CheckResult::Ptr cr = service->GetLastCheckResult();
+
                if (!cr)
                        ss.services_pending++;
+
                if (!service->IsReachable())
                        ss.services_unreachable++;
 
@@ -209,6 +210,11 @@ ServiceStatistics CIB::CalculateServiceStats()
                        ss.services_in_downtime++;
                if (service->IsAcknowledged())
                        ss.services_acknowledged++;
+
+               if (service->GetHandled())
+                       ss.services_handled++;
+               if (service->GetProblem())
+                       ss.services_problem++;
        }
 
        return ss;
@@ -238,6 +244,11 @@ HostStatistics CIB::CalculateHostStats()
                        hs.hosts_in_downtime++;
                if (host->IsAcknowledged())
                        hs.hosts_acknowledged++;
+
+               if (host->GetHandled())
+                       hs.hosts_handled++;
+               if (host->GetProblem())
+                       hs.hosts_problem++;
        }
 
        return hs;
@@ -315,6 +326,8 @@ void CIB::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) {
        status->Set("num_services_flapping", ss.services_flapping);
        status->Set("num_services_in_downtime", ss.services_in_downtime);
        status->Set("num_services_acknowledged", ss.services_acknowledged);
+       status->Set("num_services_handled", ss.services_handled);
+       status->Set("num_services_problem", ss.services_problem);
 
        double uptime = Utility::GetTime() - Application::GetStartTime();
        status->Set("uptime", uptime);
@@ -328,4 +341,6 @@ void CIB::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) {
        status->Set("num_hosts_flapping", hs.hosts_flapping);
        status->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
        status->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
+       status->Set("num_hosts_handled", hs.hosts_handled);
+       status->Set("num_hosts_problem", hs.hosts_problem);
 }
index 23a81f9519529267a82267bf15df1d1133b1f612..2abbb46001b6308ef0892c1596a7dd9a60df4a2e 100644 (file)
@@ -30,6 +30,8 @@ struct ServiceStatistics {
        double services_flapping;
        double services_in_downtime;
        double services_acknowledged;
+       double services_handled;
+       double services_problem;
 };
 
 struct HostStatistics {
@@ -40,6 +42,8 @@ struct HostStatistics {
        double hosts_flapping;
        double hosts_in_downtime;
        double hosts_acknowledged;
+       double hosts_handled;
+       double hosts_problem;
 };
 
 /**
index f8c283a0d1db9c42dda3267ff1a34e4489425b09..451f009da952694e770636ecbe8cc1efc3cd5448 100644 (file)
@@ -247,6 +247,12 @@ bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr
                } else if (macro == "num_services_acknowledged") {
                        *result = ss.services_acknowledged;
                        return true;
+               } else if (macro == "num_services_handled") {
+                       *result = ss.services_handled;
+                       return true;
+               } else if (macro == "num_services_problem") {
+                       *result = ss.services_problem;
+                       return true;
                }
        }
        else if (macro.Contains("num_hosts")) {
@@ -273,6 +279,12 @@ bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr
                } else if (macro == "num_hosts_acknowledged") {
                        *result = hs.hosts_acknowledged;
                        return true;
+               } else if (macro == "num_hosts_handled") {
+                       *result = hs.hosts_handled;
+                       return true;
+               } else if (macro == "num_hosts_problem") {
+                       *result = hs.hosts_problem;
+                       return true;
                }
        }
 
index 59dfbdf78787829e7d9bc0c5f53ef47713d11ba3..3f46fba81e76eaacd9d31166b219dbafa827a915 100644 (file)
@@ -99,6 +99,8 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
        perfdata->Add(new PerfdataValue("num_services_flapping", ss.services_flapping));
        perfdata->Add(new PerfdataValue("num_services_in_downtime", ss.services_in_downtime));
        perfdata->Add(new PerfdataValue("num_services_acknowledged", ss.services_acknowledged));
+       perfdata->Add(new PerfdataValue("num_services_handled", ss.services_handled));
+       perfdata->Add(new PerfdataValue("num_services_problem", ss.services_problem));
 
        double uptime = Utility::GetTime() - Application::GetStartTime();
        perfdata->Add(new PerfdataValue("uptime", uptime));
@@ -112,6 +114,8 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
        perfdata->Add(new PerfdataValue("num_hosts_flapping", hs.hosts_flapping));
        perfdata->Add(new PerfdataValue("num_hosts_in_downtime", hs.hosts_in_downtime));
        perfdata->Add(new PerfdataValue("num_hosts_acknowledged", hs.hosts_acknowledged));
+       perfdata->Add(new PerfdataValue("num_hosts_handled", hs.hosts_handled));
+       perfdata->Add(new PerfdataValue("num_hosts_problem", hs.hosts_problem));
 
        std::vector<Endpoint::Ptr> endpoints = ConfigType::GetObjectsByType<Endpoint>();