Refactor status/perfdata stats registry.

Fixes #5622
This commit is contained in:
Michael Friedrich 2014-02-18 10:53:44 +01:00
parent de79c1232d
commit f890a7ae8c
33 changed files with 262 additions and 83 deletions

View File

@ -31,11 +31,29 @@
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();
}

View 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;

View 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());

View 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);
return bag;
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 std::make_pair(status, perfdata);
}

View 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;

View 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;
}

View 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;
}

View 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;
}

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

View 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;
}

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

View 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;
}

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

View 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;
}

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

View 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;
}

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

View 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;
}

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

View 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;
}

View 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;
}

View 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
}

View 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;
}

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

View 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)
}

View 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;
}

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

View 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;

View File

@ -60,6 +60,8 @@ public:
void SetExceptionCallback(const ExceptionCallback& callback);
size_t GetLength(void);
private:
int m_ID;
static int m_NextID;

View 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>();

View 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;
}

View 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;
}

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