From 7d28e95dba69eaf98ffdc38ed5be20a6db0553e6 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 7 Nov 2013 17:29:45 +0100 Subject: [PATCH] Livestatus: Add servive_checks(_rate) columns to status table. Refs #4655 Refs #2762 --- components/livestatus/query.cpp | 4 ++-- components/livestatus/query.h | 2 +- components/livestatus/statustable.cpp | 16 ++++++++++++++-- components/livestatus/statustable.h | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index de43a2076..c768d22ff 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -47,7 +47,7 @@ using namespace livestatus; static int l_ExternalCommands = 0; static boost::mutex l_QueryMutex; -Query::Query(const std::vector& lines, const String& log_path) +Query::Query(const std::vector& lines, const String& compat_log_path) : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1), m_LogTimeFrom(0), m_LogTimeUntil(static_cast(Utility::GetTime())) { @@ -64,7 +64,7 @@ Query::Query(const std::vector& lines, const String& log_path) } Log(LogDebug, "livestatus", msg); - m_CompatLogPath = log_path; + m_CompatLogPath = compat_log_path; /* default separators */ m_Separators.push_back("\n"); diff --git a/components/livestatus/query.h b/components/livestatus/query.h index adb3bd5e3..d7cdbb02b 100644 --- a/components/livestatus/query.h +++ b/components/livestatus/query.h @@ -47,7 +47,7 @@ class Query : public Object public: DECLARE_PTR_TYPEDEFS(Query); - Query(const std::vector& lines, const String& log_path); + Query(const std::vector& lines, const String& compat_log_path); bool Execute(const Stream::Ptr& stream); diff --git a/components/livestatus/statustable.cpp b/components/livestatus/statustable.cpp index 36824e117..eed18ec6b 100644 --- a/components/livestatus/statustable.cpp +++ b/components/livestatus/statustable.cpp @@ -47,8 +47,8 @@ void StatusTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "connections", Column(&StatusTable::ConnectionsAccessor, objectAccessor)); table->AddColumn(prefix + "connections_rate", Column(&StatusTable::ConnectionsRateAccessor, objectAccessor)); - table->AddColumn(prefix + "service_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "service_checks_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "service_checks", Column(&StatusTable::ServiceChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "service_checks_rate", Column(&StatusTable::ServiceChecksRateAccessor, objectAccessor)); table->AddColumn(prefix + "host_checks", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "host_checks_rate", Column(&Table::ZeroAccessor, objectAccessor)); @@ -122,6 +122,18 @@ Value StatusTable::ConnectionsRateAccessor(const Value& row) return (LivestatusListener::GetConnections() / (Utility::GetTime() - Application::GetStartTime())); } +Value StatusTable::ServiceChecksAccessor(const Value& row) +{ + long timespan = static_cast(Utility::GetTime() - Application::GetStartTime()); + return CIB::GetActiveChecksStatistics(timespan); +} + +Value StatusTable::ServiceChecksRateAccessor(const Value& row) +{ + long timespan = static_cast(Utility::GetTime() - Application::GetStartTime()); + return (CIB::GetActiveChecksStatistics(timespan) / (Utility::GetTime() - Application::GetStartTime())); +} + Value StatusTable::ExternalCommandsAccessor(const Value& row) { return Query::GetExternalCommands(); diff --git a/components/livestatus/statustable.h b/components/livestatus/statustable.h index b8584df55..6d893d258 100644 --- a/components/livestatus/statustable.h +++ b/components/livestatus/statustable.h @@ -47,6 +47,8 @@ protected: static Value ConnectionsAccessor(const Value& row); static Value ConnectionsRateAccessor(const Value& row); + static Value ServiceChecksAccessor(const Value& row); + static Value ServiceChecksRateAccessor(const Value& row); static Value ExternalCommandsAccessor(const Value& row); static Value ExternalCommandsRateAccessor(const Value& row); static Value NagiosPidAccessor(const Value& row);