From 78c26f055a4f5d3d60a18f6b5ffb9b950a0433d6 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 2 Aug 2018 14:31:06 +0200 Subject: [PATCH] Provide collected cluster stats via /v1/status --- lib/remote/statsreporter.cpp | 8 ++++++++ lib/remote/statsreporter.hpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lib/remote/statsreporter.cpp b/lib/remote/statsreporter.cpp index 1734d8b5f..77225bd40 100644 --- a/lib/remote/statsreporter.cpp +++ b/lib/remote/statsreporter.cpp @@ -24,6 +24,7 @@ #include "base/function.hpp" #include "base/objectlock.hpp" #include "base/scriptglobal.hpp" +#include "base/statsfunction.hpp" #include "base/utility.hpp" #include "base/value.hpp" #include "remote/apifunction.hpp" @@ -38,6 +39,8 @@ using namespace icinga; REGISTER_APIFUNCTION(ClusterStats, event, &StatsReporter::ClusterStatsAPIHandler); +REGISTER_STATSFUNCTION(ClusterStats, &StatsReporter::StatsFunc); + StatsReporter StatsReporter::m_Instance; StatsReporter::StatsReporter() @@ -185,3 +188,8 @@ void StatsReporter::ClusterStatsHandler(const String& endpoint, const Dictionary boost::mutex::scoped_lock lock (m_Mutex); m_SecondaryStats[endpoint] = stats; } + +void StatsReporter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) +{ + status->Set("cluster", m_Instance.GenerateStats()); +} diff --git a/lib/remote/statsreporter.hpp b/lib/remote/statsreporter.hpp index a61144800..42d77370a 100644 --- a/lib/remote/statsreporter.hpp +++ b/lib/remote/statsreporter.hpp @@ -20,6 +20,7 @@ #ifndef STATSREPORTER_H #define STATSREPORTER_H +#include "base/array.hpp" #include "base/dictionary.hpp" #include "base/string.hpp" #include "base/timer.hpp" @@ -40,6 +41,7 @@ class StatsReporter { public: static Value ClusterStatsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); + static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); private: StatsReporter();