]> granicus.if.org Git - icinga2/commitdiff
Refactor status/perfdata stats registry.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 18 Feb 2014 09:53:44 +0000 (10:53 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 20 Feb 2014 14:25:58 +0000 (15:25 +0100)
Fixes #5622

33 files changed:
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
components/cluster/clusterchecktask.cpp
components/cluster/clusterlistener.cpp
components/cluster/clusterlistener.h
components/compat/checkresultreader.cpp
components/compat/compatlogger.cpp
components/compat/externalcommandlistener.cpp
components/compat/externalcommandlistener.h
components/compat/statusdatawriter.cpp
components/compat/statusdatawriter.h
components/db_ido_mysql/idomysqlconnection.cpp
components/db_ido_mysql/idomysqlconnection.h
components/db_ido_pgsql/idopgsqlconnection.cpp
components/db_ido_pgsql/idopgsqlconnection.h
components/livestatus/listener.cpp
components/livestatus/listener.h
components/notification/notificationcomponent.cpp
components/notification/notificationcomponent.h
components/perfdata/graphitewriter.cpp
components/perfdata/perfdatawriter.cpp
doc/4.3-object-types.md
lib/base/filelogger.cpp
lib/base/filelogger.h
lib/base/statsfunction.h
lib/base/sysloglogger.cpp
lib/base/sysloglogger.h
lib/base/workqueue.cpp
lib/base/workqueue.h
lib/icinga/cib.cpp
lib/icinga/icingaapplication.cpp
lib/icinga/icingastatuswriter.cpp
lib/icinga/icingastatuswriter.h

index 3245027fafdac4c1bdf41fdf1fdb99bca7cf0165..4e59d35359f3ecc3b950ca53caf85c4c0f9df0fd 100644 (file)
 using namespace icinga;
 
 REGISTER_TYPE(CheckerComponent);
+
 REGISTER_STATSFUNCTION(CheckerComponentStats, &CheckerComponent::StatsFunc);
 
 Value CheckerComponent::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       status->Set("checkercomponent_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const CheckerComponent::Ptr& checker, DynamicType::GetObjects<CheckerComponent>()) {
+               unsigned long idle = checker->GetIdleServices();
+               unsigned long pending = checker->GetPendingServices();
+
+               Dictionary::Ptr stats = make_shared<Dictionary>();
+               stats->Set("idle", idle);
+               stats->Set("pending", pending);
+
+               nodes->Set(checker->GetName(), stats);
+
+               String perfdata_prefix = "checkercomponent_" + checker->GetName() + "_";
+               perfdata->Set(perfdata_prefix + "idle", idle);
+               perfdata->Set(perfdata_prefix + "pending", pending);
+       }
+
+       status->Set("checkercomponent", nodes);
 
        return 0;
 }
@@ -241,3 +259,17 @@ void CheckerComponent::NextCheckChangedHandler(const Service::Ptr& service)
        idx.insert(service);
        m_CV.notify_all();
 }
+
+unsigned long CheckerComponent::GetIdleServices(void)
+{
+       boost::mutex::scoped_lock lock(m_Mutex);
+
+       return m_IdleServices.size();
+}
+
+unsigned long CheckerComponent::GetPendingServices(void)
+{
+       boost::mutex::scoped_lock lock(m_Mutex);
+
+       return m_PendingServices.size();
+}
index 63cc70a1adaea3e7f9bc7d3caa83832c548df49f..b82cea0a3c39309c8b79ae2db43232e054d7de13 100644 (file)
@@ -58,6 +58,7 @@ class CheckerComponent : public ObjectImpl<CheckerComponent>
 {
 public:
        DECLARE_PTR_TYPEDEFS(CheckerComponent);
+       DECLARE_TYPENAME(CheckerComponent);
 
        typedef boost::multi_index_container<
                Service::Ptr,
@@ -72,6 +73,8 @@ public:
        virtual void Stop(void);
 
        static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       unsigned long GetIdleServices(void);
+       unsigned long GetPendingServices(void);
 
 private:
        boost::mutex m_Mutex;
index ff135a1824b9974fb01b12b98a2b37a3bee0c829..4b56d7924bbb01c63fade4d3cca3138a8e19cb99 100644 (file)
@@ -37,19 +37,22 @@ REGISTER_SCRIPTFUNCTION(ClusterCheck, &ClusterCheckTask::ScriptFunc);
 
 CheckResult::Ptr ClusterCheckTask::ScriptFunc(const Service::Ptr&)
 {
-       Dictionary::Ptr status;
+       /* fetch specific cluster status */
+       std::pair<Dictionary::Ptr, Dictionary::Ptr> stats;
        BOOST_FOREACH(const ClusterListener::Ptr& cluster_listener, DynamicType::GetObjects<ClusterListener>()) {
                /* XXX there's only one cluster listener */
-               status = cluster_listener->GetClusterStatus();
+               stats = cluster_listener->GetClusterStatus();
        }
 
+       Dictionary::Ptr status = stats.first;
+
+       /* use feature stats perfdata */
+       std::pair<Dictionary::Ptr, Dictionary::Ptr> feature_stats = CIB::GetFeatureStats();
+       Dictionary::Ptr perfdata = feature_stats.second;
+
        String connected_endpoints = FormatArray(status->Get("conn_endpoints"));
        String not_connected_endpoints = FormatArray(status->Get("not_conn_endpoints"));
 
-       /* remove unneeded perfdata */
-       status->Set("conn_endpoints", Empty);
-       status->Set("not_conn_endpoints", Empty);
-
        ServiceState state = StateOK;
        String output = "Icinga 2 Cluster is running: Connected Endpoints: "+ Convert::ToString(status->Get("num_conn_endpoints")) + " (" +
            connected_endpoints + ").";
@@ -62,7 +65,7 @@ CheckResult::Ptr ClusterCheckTask::ScriptFunc(const Service::Ptr&)
 
        CheckResult::Ptr cr = make_shared<CheckResult>();
        cr->SetOutput(output);
-       cr->SetPerformanceData(status);
+       cr->SetPerformanceData(perfdata);
        cr->SetState(state);
        cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
index f31ffe8553ae455ce5e816e7d9e38665cd2a4b68..3c0f451c5daa8aafdad3f23c7868a4d191571368 100644 (file)
@@ -42,12 +42,21 @@ REGISTER_STATSFUNCTION(ClusterListenerStats, &ClusterListener::StatsFunc);
 
 Value ClusterListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       status->Set("clusterlistener_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+       std::pair<Dictionary::Ptr, Dictionary::Ptr> stats;
 
        BOOST_FOREACH(const ClusterListener::Ptr& cluster_listener, DynamicType::GetObjects<ClusterListener>()) {
-               status->Set("clusterlistener_" + cluster_listener->GetName(), cluster_listener->GetClusterStatus());
+               stats = cluster_listener->GetClusterStatus();
+               nodes->Set(cluster_listener->GetName(), stats.first);
+
+               String perfdata_prefix = "clusterlistener_" + cluster_listener->GetName() + "_";
+               BOOST_FOREACH(Dictionary::Pair const& kv, stats.second) {
+                       perfdata->Set(perfdata_prefix + kv.first, kv.second);
+               }
        }
 
+       status->Set("clusterlistener", nodes);
+
        return 0;
 }
 
@@ -1584,13 +1593,14 @@ bool ClusterListener::SupportsFeature(const String& name)
        return !type->GetObjects().empty();
 }
 
-Dictionary::Ptr ClusterListener::GetClusterStatus(void)
+std::pair<Dictionary::Ptr, Dictionary::Ptr> ClusterListener::GetClusterStatus(void)
 {
-       Dictionary::Ptr bag = make_shared<Dictionary>();
+       Dictionary::Ptr status = make_shared<Dictionary>();
+       Dictionary::Ptr perfdata = make_shared<Dictionary>();
 
        /* cluster stats */
-       bag->Set("node", IcingaApplication::GetInstance()->GetNodeName());
-       bag->Set("identity", GetIdentity());
+       status->Set("node", IcingaApplication::GetInstance()->GetNodeName());
+       status->Set("identity", GetIdentity());
 
        double count_endpoints = 0;
        Array::Ptr not_connected_endpoints = make_shared<Array>();
@@ -1608,12 +1618,16 @@ Dictionary::Ptr ClusterListener::GetClusterStatus(void)
        std::sort(not_connected_endpoints->Begin(), not_connected_endpoints->End());
        std::sort(connected_endpoints->Begin(), connected_endpoints->End());
 
-       bag->Set("num_endpoints", count_endpoints);
-       bag->Set("num_conn_endpoints", connected_endpoints->GetLength());
-       bag->Set("num_not_conn_endpoints", not_connected_endpoints->GetLength());
-       bag->Set("conn_endpoints", connected_endpoints);
-       bag->Set("not_conn_endpoints", not_connected_endpoints);
+       status->Set("num_endpoints", count_endpoints);
+       status->Set("num_conn_endpoints", connected_endpoints->GetLength());
+       status->Set("num_not_conn_endpoints", not_connected_endpoints->GetLength());
+       status->Set("conn_endpoints", connected_endpoints);
+       status->Set("not_conn_endpoints", not_connected_endpoints);
+
+       perfdata->Set("num_endpoints", count_endpoints);
+       perfdata->Set("num_conn_endpoints", connected_endpoints->GetLength());
+       perfdata->Set("num_not_conn_endpoints", not_connected_endpoints->GetLength());
 
-       return bag;
+       return std::make_pair(status, perfdata);
 }
 
index 428ff5d69f4a4e5fb477a32f2eb8a67d49f80919..9f8e3f40f46f8d362a5ae01471b1ecb2ee9d378d 100644 (file)
@@ -53,7 +53,7 @@ public:
        shared_ptr<SSL_CTX> GetSSLContext(void) const;
        String GetClusterDir(void) const;
 
-        Dictionary::Ptr GetClusterStatus(void);
+        std::pair<Dictionary::Ptr, Dictionary::Ptr> GetClusterStatus(void);
 
 private:
        shared_ptr<SSL_CTX> m_SSLContext;
index 664561b8d59ccb287f7a2017562b0110e55e74a5..931228751a8218fa70316684a40c1c628b3a2068 100644 (file)
@@ -40,8 +40,13 @@ REGISTER_STATSFUNCTION(CheckResultReaderStats, &CheckResultReader::StatsFunc);
 
 Value CheckResultReader::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("checkresultreader_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const CheckResultReader::Ptr& checkresultreader, DynamicType::GetObjects<CheckResultReader>()) {
+               nodes->Set(checkresultreader->GetName(), 1); //add more stats
+       }
+
+       status->Set("checkresultreader", nodes);
 
        return 0;
 }
index 252c7566a9523ee01d4f38fc8206858c51d0ec23..44978b4856034934f6024a3c040dd62748c7e556 100644 (file)
@@ -47,8 +47,13 @@ REGISTER_STATSFUNCTION(CompatLoggerStats, &CompatLogger::StatsFunc);
 
 Value CompatLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("compatlogger_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const CompatLogger::Ptr& compat_logger, DynamicType::GetObjects<CompatLogger>()) {
+               nodes->Set(compat_logger->GetName(), 1); //add more stats
+       }
+
+       status->Set("compatlogger", nodes);
 
        return 0;
 }
index 42efa38b94c87f1d26f5cbe819824a77c0d83d62..a9f0e505a5a5ca6a677ae5e58fce51d429dad4c0 100644 (file)
@@ -33,8 +33,13 @@ REGISTER_STATSFUNCTION(ExternalCommandListenerStats, &ExternalCommandListener::S
 
 Value ExternalCommandListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("externalcommandlisterner_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const ExternalCommandListener::Ptr& externalcommandlistener, DynamicType::GetObjects<ExternalCommandListener>()) {
+               nodes->Set(externalcommandlistener->GetName(), 1); //add more stats
+       }
+
+       status->Set("externalcommandlistener", nodes);
 
        return 0;
 }
index d8dce048a0d57fe6fc401ffd8875677829103341..19070f64cfddd32805ea55e6144fbd0e0f4130d5 100644 (file)
@@ -37,6 +37,7 @@ class ExternalCommandListener : public ObjectImpl<ExternalCommandListener>
 {
 public:
        DECLARE_PTR_TYPEDEFS(ExternalCommandListener);
+        DECLARE_TYPENAME(ExternalCommandListener);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index c90571e01f984aebfb2d599553a8368472038690..31397832cd42840d7c5466e37389dd66a3139937 100644 (file)
@@ -48,8 +48,13 @@ REGISTER_STATSFUNCTION(StatusDataWriterStats, &StatusDataWriter::StatsFunc);
 
 Value StatusDataWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("statusdatawriter_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const StatusDataWriter::Ptr& statusdatawriter, DynamicType::GetObjects<StatusDataWriter>()) {
+               nodes->Set(statusdatawriter->GetName(), 1); //add more stats
+       }
+
+       status->Set("statusdatawriter", nodes);
 
        return 0;
 }
index e1cb6c995b7afbafd5e4dca47a0cfc141528db98..64b9c38c9932c7005de2641969a2425e268c6cd6 100644 (file)
@@ -41,6 +41,7 @@ class StatusDataWriter : public ObjectImpl<StatusDataWriter>
 {
 public:
        DECLARE_PTR_TYPEDEFS(StatusDataWriter);
+       DECLARE_TYPENAME(StatusDataWriter);
 
        static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index 701c9fd1b8f9eab9cecde818b93a016fe24cff6d..9485ae2d2aa580f0a1e4be12fe982f795771b14b 100644 (file)
@@ -40,8 +40,22 @@ REGISTER_STATSFUNCTION(IdoMysqlConnectionStats, &IdoMysqlConnection::StatsFunc);
 
 Value IdoMysqlConnection::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("ido_mysql_version_req", SCHEMA_VERSION);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const IdoMysqlConnection::Ptr& idomysqlconnection, DynamicType::GetObjects<IdoMysqlConnection>()) {
+               size_t items = idomysqlconnection->m_QueryQueue.GetLength();
+
+               Dictionary::Ptr stats = make_shared<Dictionary>();
+               stats->Set("version", SCHEMA_VERSION);
+               stats->Set("instance_name", idomysqlconnection->GetInstanceName());
+               stats->Set("query_queue_items", items);
+
+               nodes->Set(idomysqlconnection->GetName(), stats);
+
+               perfdata->Set("idomysqlconnection_" + idomysqlconnection->GetName() + "_query_queue_items", items);
+       }
+
+       status->Set("idomysqlconnection", nodes);
 
        return 0;
 }
index 26f8425bd8a4ad0676892f6763fba271651f15df..d935e0b1220e8dc598bd3862b3895736560a6561 100644 (file)
@@ -40,6 +40,7 @@ class IdoMysqlConnection : public ObjectImpl<IdoMysqlConnection>
 {
 public:
        DECLARE_PTR_TYPEDEFS(IdoMysqlConnection);
+       DECLARE_TYPENAME(IdoMysqlConnection);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index 128bd278c1604c238a34577beb7cbe5beaf12eb1..d8ae808b2b609560b10c9ec3b7d0b515597e6c5d 100644 (file)
@@ -42,8 +42,22 @@ REGISTER_STATSFUNCTION(IdoPgsqlConnectionStats, &IdoPgsqlConnection::StatsFunc);
 
 Value IdoPgsqlConnection::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("ido_pgsql_version_req", SCHEMA_VERSION);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const IdoPgsqlConnection::Ptr& idopgsqlconnection, DynamicType::GetObjects<IdoPgsqlConnection>()) {
+               size_t items = idopgsqlconnection->m_QueryQueue.GetLength();
+
+               Dictionary::Ptr stats = make_shared<Dictionary>();
+               stats->Set("version", SCHEMA_VERSION);
+               stats->Set("instance_name", idopgsqlconnection->GetInstanceName());
+               stats->Set("query_queue_items", items);
+
+               nodes->Set(idopgsqlconnection->GetName(), stats);
+
+               perfdata->Set("idopgsqlconnection_" + idopgsqlconnection->GetName() + "_query_queue_items", items);
+       }
+
+       status->Set("idopgsqlconnection", nodes);
 
        return 0;
 }
index 3de6c55607d9245df01a9249f43bdc521e1ae816..06708652bee4dc5db1c11b42ed7fade47f9622cc 100644 (file)
@@ -40,6 +40,7 @@ class IdoPgsqlConnection : public ObjectImpl<IdoPgsqlConnection>
 {
 public:
        DECLARE_PTR_TYPEDEFS(IdoPgsqlConnection);
+        DECLARE_TYPENAME(IdoPgsqlConnection);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index 5b233277f70b3dace3653b52a32f5d40d2e324ba..340f0e6eb1d8de7fe0830cce27348b07b5df7625 100644 (file)
@@ -45,8 +45,18 @@ REGISTER_STATSFUNCTION(LivestatusListenerStats, &LivestatusListener::StatsFunc);
 
 Value LivestatusListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("livestatus_connections", l_Connections);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const LivestatusListener::Ptr& livestatuslistener, DynamicType::GetObjects<LivestatusListener>()) {
+               Dictionary::Ptr stats = make_shared<Dictionary>();
+               stats->Set("connections", l_Connections);
+
+               nodes->Set(livestatuslistener->GetName(), stats);
+
+               perfdata->Set("livestatuslistener_" + livestatuslistener->GetName() + "_connections", l_Connections);
+       }
+
+       status->Set("livestatuslistener", nodes);
 
        return 0;
 }
index 8f106a9035ddbd4804dfd4de236fd2f55d5883eb..294e14e3570b539cc4fd69814d628445eb46a823 100644 (file)
@@ -37,6 +37,7 @@ class LivestatusListener : public ObjectImpl<LivestatusListener>
 {
 public:
        DECLARE_PTR_TYPEDEFS(LivestatusListener);
+        DECLARE_TYPENAME(LivestatusListener);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index 2843e3051963f8bff7b0b5e3559f022b2364cf6a..7444b7c09ffd1c6f80ce12fc678da52effe3f857 100644 (file)
@@ -35,8 +35,13 @@ REGISTER_STATSFUNCTION(NotificationComponentStats, &NotificationComponent::Stats
 
 Value NotificationComponent::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("notification_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const NotificationComponent::Ptr& notification_component, DynamicType::GetObjects<NotificationComponent>()) {
+               nodes->Set(notification_component->GetName(), 1); //add more stats
+       }
+
+       status->Set("notificationcomponent", nodes);
 
        return 0;
 }
index ddb0f6ebf6d65b8e13eef421f04e1e9d63a87497..8b6d2a33c352568641d2896aaa7a082d806edfa2 100644 (file)
@@ -35,6 +35,7 @@ class NotificationComponent : public ObjectImpl<NotificationComponent>
 {
 public:
        DECLARE_PTR_TYPEDEFS(NotificationComponent);
+        DECLARE_TYPENAME(NotificationComponent);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index ce8c613688132214b6b8768d3058a716015cf7e0..80550a3bbe97ccd0ce8c44a38b37dcff8758b2b6 100644 (file)
@@ -49,8 +49,13 @@ REGISTER_STATSFUNCTION(GraphiteWriterStats, &GraphiteWriter::StatsFunc);
 
 Value GraphiteWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("graphite_writer_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const GraphiteWriter::Ptr& graphitewriter, DynamicType::GetObjects<GraphiteWriter>()) {
+               nodes->Set(graphitewriter->GetName(), 1); //add more stats
+       }
+
+       status->Set("graphitewriter", nodes);
 
        return 0;
 }
index 32f2623ef92462662c0d3279dc5196b39d741aed..385fd1a837aeec68afa6be7dcc5617c9da35db21 100644 (file)
@@ -38,8 +38,13 @@ REGISTER_STATSFUNCTION(PerfdataWriterStats, &PerfdataWriter::StatsFunc);
 
 Value PerfdataWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("perfdatawriter_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const PerfdataWriter::Ptr& perfdatawriter, DynamicType::GetObjects<PerfdataWriter>()) {
+               nodes->Set(perfdatawriter->GetName(), 1); //add more stats
+       }
+
+       status->Set("perfdatawriter", nodes);
 
        return 0;
 }
index abf294f89c340daa38060c07dce29ce22703de1b..354de33db4048832a79908b5d7f94dc06306c59d 100644 (file)
@@ -837,10 +837,8 @@ a defined JSON file.
 
 Example:
 
-    library "icinga"
-
     object IcingaStatusWriter "status" {
-      status_path = (IcingaLocalStateDir + "/cache/icinga2/status.json),
+      status_path = (IcingaLocalStateDir + "/cache/icinga2/status.json)",
       update_interval = 15s
     }
 
index 3f90c806cb1b864d4bb2adb5d565369f4a592edd..c1f55549d9b5ed0535093ad24a244438fd6e55c1 100644 (file)
@@ -30,8 +30,13 @@ REGISTER_STATSFUNCTION(FileLoggerStats, &FileLogger::StatsFunc);
 
 Value FileLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("filelogger_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const FileLogger::Ptr& filelogger, DynamicType::GetObjects<FileLogger>()) {
+               nodes->Set(filelogger->GetName(), 1); //add more stats
+       }
+
+       status->Set("filelogger", nodes);
 
        return 0;
 }
index 2c6b6572f9b83e3ee03317af9799cfcef69ad16c..00416b898cc23fa29968c23e2d14239bb903e38f 100644 (file)
@@ -35,6 +35,7 @@ class I2_BASE_API FileLogger : public ObjectImpl<FileLogger>
 {
 public:
        DECLARE_PTR_TYPEDEFS(FileLogger);
+        DECLARE_TYPENAME(FileLogger);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index 4acbd322d487497e539fd8c947f551a256bdf438..1dfaf6be2b1c53bf568ec57f5e3a316b613e8b3e 100644 (file)
@@ -74,7 +74,7 @@ public:
 };
 
 #define REGISTER_STATSFUNCTION(name, callback) \
-       I2_EXPORT icinga::RegisterStatsFunctionHelper g_RegisterSF_ ## name(#name, callback)
+       I2_EXPORT icinga::RegisterStatsFunctionHelper g_RegisterStF_ ## name(#name, callback)
 
 }
 
index 64e203862559985d105c8b770206823a15d51050..0f9809321a6f6e186c4f48c966101b483a3d2dc1 100644 (file)
@@ -30,8 +30,13 @@ REGISTER_STATSFUNCTION(SyslogLoggerStats, &SyslogLogger::StatsFunc);
 
 Value SyslogLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("sysloglogger_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const SyslogLogger::Ptr& sysloglogger, DynamicType::GetObjects<SyslogLogger>()) {
+               nodes->Set(sysloglogger->GetName(), 1); //add more stats
+       }
+
+       status->Set("sysloglogger", nodes);
 
        return 0;
 }
index a16edee7a832e584456e482e7fd586c245d41126..ff08589ce9809a162959a502f01f2e052a11a3f3 100644 (file)
@@ -36,6 +36,7 @@ class I2_BASE_API SyslogLogger : public ObjectImpl<SyslogLogger>
 {
 public:
        DECLARE_PTR_TYPEDEFS(SyslogLogger);
+        DECLARE_TYPENAME(SyslogLogger);
 
         static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
 
index 1a7cf1c3e8540d449e3090b6c5e6bdfb63b644ee..20a07af3c94e293cb3046b46fb0aaeeb8bc3a909 100644 (file)
@@ -107,6 +107,13 @@ void WorkQueue::SetExceptionCallback(const ExceptionCallback& callback)
        m_ExceptionCallback = callback;
 }
 
+size_t WorkQueue::GetLength(void)
+{
+       boost::mutex::scoped_lock lock(m_Mutex);
+
+       return m_Items.size();
+}
+
 void WorkQueue::DefaultExceptionCallback(boost::exception_ptr exp)
 {
        throw;
index fbaf76e9bbf67fcde323924930c38ce82a41a746..258a0bc337a743fac2437c6fdd6479c99ca85b8c 100644 (file)
@@ -60,6 +60,8 @@ public:
 
        void SetExceptionCallback(const ExceptionCallback& callback);
 
+       size_t GetLength(void);
+
 private:
        int m_ID;
        static int m_NextID;
index 424be3b7561425853942608f6b0348cf45c35a44..12a80e5fb08fe6e783d8219ec0a8d92d575e30c1 100644 (file)
@@ -169,7 +169,10 @@ HostStatistics CIB::CalculateHostStats(void)
        return hs;
 }
 
-
+/*
+ * 'perfdata' must be a flat dictionary with double values
+ * 'status' dictionary can contain multiple levels of dictionaries
+ */
 std::pair<Dictionary::Ptr, Dictionary::Ptr> CIB::GetFeatureStats(void)
 {
        Dictionary::Ptr status = make_shared<Dictionary>();
index 5b651afad8d4a5a83e16fcbc8973caca66f913de..fe6fe469a07e790f2da4c33b34ed6e296b45f46a 100644 (file)
@@ -50,8 +50,24 @@ REGISTER_STATSFUNCTION(IcingaApplicationStats, &IcingaApplication::StatsFunc);
 
 Value IcingaApplication::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("icingaapplication_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const IcingaApplication::Ptr& icingaapplication, DynamicType::GetObjects<IcingaApplication>()) {
+               Dictionary::Ptr stats = make_shared<Dictionary>();
+               stats->Set("node_name", icingaapplication->GetNodeName());
+               stats->Set("enable_notifications", icingaapplication->GetEnableNotifications());
+               stats->Set("enable_event_handlers", icingaapplication->GetEnableEventHandlers());
+               stats->Set("enable_flapping", icingaapplication->GetEnableFlapping());
+               stats->Set("enable_checks", icingaapplication->GetEnableChecks());
+               stats->Set("enable_perfdata", icingaapplication->GetEnablePerfdata());
+               stats->Set("pid", Utility::GetPid());
+               stats->Set("program_start", Application::GetStartTime());
+               stats->Set("version", Application::GetVersion());
+
+               nodes->Set(icingaapplication->GetName(), stats);
+       }
+
+       status->Set("icingaapplication", nodes);
 
        return 0;
 }
index c79ab43e3108e1d78c3233d90fe9e02e33d05384..612b929a0a3529f6ab17c6de53478a47423bc98d 100644 (file)
@@ -48,8 +48,13 @@ REGISTER_STATSFUNCTION(IcingaStatusWriterStats, &IcingaStatusWriter::StatsFunc);
 
 Value IcingaStatusWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 {
-       /* FIXME */
-       status->Set("icingastatuswriter_", 1);
+       Dictionary::Ptr nodes = make_shared<Dictionary>();
+
+       BOOST_FOREACH(const IcingaStatusWriter::Ptr& icingastatuswriter, DynamicType::GetObjects<IcingaStatusWriter>()) {
+               nodes->Set(icingastatuswriter->GetName(), 1); //add more stats
+       }
+
+       status->Set("icingastatuswriter", nodes);
 
        return 0;
 }
@@ -85,50 +90,54 @@ Dictionary::Ptr IcingaStatusWriter::GetStatusData(void)
        bag->Set("feature_perfdata", stats.second);
 
        /* icinga stats */
+       Dictionary::Ptr icinga_stats = make_shared<Dictionary>();
+
        double interval = Utility::GetTime() - Application::GetStartTime();
 
        if (interval > 60)
                interval = 60;
 
-       bag->Set("active_checks", CIB::GetActiveChecksStatistics(interval) / interval);
-       bag->Set("passive_checks", CIB::GetPassiveChecksStatistics(interval) / interval);
+       icinga_stats->Set("active_checks", CIB::GetActiveChecksStatistics(interval) / interval);
+       icinga_stats->Set("passive_checks", CIB::GetPassiveChecksStatistics(interval) / interval);
 
-       bag->Set("active_checks_1min", CIB::GetActiveChecksStatistics(60));
-       bag->Set("passive_checks_1min", CIB::GetPassiveChecksStatistics(60));
-       bag->Set("active_checks_5min", CIB::GetActiveChecksStatistics(60 * 5));
-       bag->Set("passive_checks_5min", CIB::GetPassiveChecksStatistics(60 * 5));
-       bag->Set("active_checks_15min", CIB::GetActiveChecksStatistics(60 * 15));
-       bag->Set("passive_checks_15min", CIB::GetPassiveChecksStatistics(60 * 15));
+       icinga_stats->Set("active_checks_1min", CIB::GetActiveChecksStatistics(60));
+       icinga_stats->Set("passive_checks_1min", CIB::GetPassiveChecksStatistics(60));
+       icinga_stats->Set("active_checks_5min", CIB::GetActiveChecksStatistics(60 * 5));
+       icinga_stats->Set("passive_checks_5min", CIB::GetPassiveChecksStatistics(60 * 5));
+       icinga_stats->Set("active_checks_15min", CIB::GetActiveChecksStatistics(60 * 15));
+       icinga_stats->Set("passive_checks_15min", CIB::GetPassiveChecksStatistics(60 * 15));
 
        ServiceCheckStatistics scs = CIB::CalculateServiceCheckStats();
 
-       bag->Set("min_latency", scs.min_latency);
-       bag->Set("max_latency", scs.max_latency);
-       bag->Set("avg_latency", scs.avg_latency);
-       bag->Set("min_execution_time", scs.min_latency);
-       bag->Set("max_execution_time", scs.max_latency);
-       bag->Set("avg_execution_time", scs.avg_execution_time);
+       icinga_stats->Set("min_latency", scs.min_latency);
+       icinga_stats->Set("max_latency", scs.max_latency);
+       icinga_stats->Set("avg_latency", scs.avg_latency);
+       icinga_stats->Set("min_execution_time", scs.min_latency);
+       icinga_stats->Set("max_execution_time", scs.max_latency);
+       icinga_stats->Set("avg_execution_time", scs.avg_execution_time);
 
        ServiceStatistics ss = CIB::CalculateServiceStats();
 
-       bag->Set("num_services_ok", ss.services_ok);
-       bag->Set("num_services_warning", ss.services_warning);
-       bag->Set("num_services_critical", ss.services_critical);
-       bag->Set("num_services_unknown", ss.services_unknown);
-       bag->Set("num_services_pending", ss.services_pending);
-       bag->Set("num_services_unreachable", ss.services_unreachable);
-       bag->Set("num_services_flapping", ss.services_flapping);
-       bag->Set("num_services_in_downtime", ss.services_in_downtime);
-       bag->Set("num_services_acknowledged", ss.services_acknowledged);
+       icinga_stats->Set("num_services_ok", ss.services_ok);
+       icinga_stats->Set("num_services_warning", ss.services_warning);
+       icinga_stats->Set("num_services_critical", ss.services_critical);
+       icinga_stats->Set("num_services_unknown", ss.services_unknown);
+       icinga_stats->Set("num_services_pending", ss.services_pending);
+       icinga_stats->Set("num_services_unreachable", ss.services_unreachable);
+       icinga_stats->Set("num_services_flapping", ss.services_flapping);
+       icinga_stats->Set("num_services_in_downtime", ss.services_in_downtime);
+       icinga_stats->Set("num_services_acknowledged", ss.services_acknowledged);
 
        HostStatistics hs = CIB::CalculateHostStats();
 
-       bag->Set("num_hosts_up", hs.hosts_up);
-       bag->Set("num_hosts_down", hs.hosts_down);
-       bag->Set("num_hosts_unreachable", hs.hosts_unreachable);
-       bag->Set("num_hosts_flapping", hs.hosts_flapping);
-       bag->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
-       bag->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
+       icinga_stats->Set("num_hosts_up", hs.hosts_up);
+       icinga_stats->Set("num_hosts_down", hs.hosts_down);
+       icinga_stats->Set("num_hosts_unreachable", hs.hosts_unreachable);
+       icinga_stats->Set("num_hosts_flapping", hs.hosts_flapping);
+       icinga_stats->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
+       icinga_stats->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
+
+       bag->Set("icinga_status", icinga_stats);
 
        return bag;
 }
index 21b07940836ac33aa81f0865a2ab5accdb44ccf5..7d534faa2eac64b495da9fba0a5fc307001227ed 100644 (file)
@@ -41,6 +41,7 @@ class IcingaStatusWriter : public ObjectImpl<IcingaStatusWriter>
 {
 public:
        DECLARE_PTR_TYPEDEFS(IcingaStatusWriter);
+       DECLARE_TYPENAME(IcingaStatusWriter);
 
        static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
        static Dictionary::Ptr GetStatusData(void);