22
22
#include " base/function.hpp"
23
23
#include " base/objectlock.hpp"
24
24
#include " base/scriptglobal.hpp"
25
+ #include " base/statsfunction.hpp"
25
26
#include " base/value.hpp"
26
27
#include " remote/apifunction.hpp"
27
28
#include " remote/endpoint.hpp"
@@ -36,6 +37,8 @@ using namespace icinga;
36
37
37
38
REGISTER_APIFUNCTION (ClusterStats, event, &StatsReporter::ClusterStatsAPIHandler);
38
39
40
+ REGISTER_STATSFUNCTION (StatsReporter, &StatsReporter::StatsFunc);
41
+
39
42
StatsReporter StatsReporter::m_Instance;
40
43
41
44
StatsReporter::StatsReporter ()
@@ -62,20 +65,7 @@ void StatsReporter::ReportStats()
62
65
for (auto & endpoint : zone->GetEndpoints ()) {
63
66
for (auto & client : endpoint->GetClients ()) {
64
67
if (!message) {
65
- Dictionary::Ptr allStats = new Dictionary;
66
-
67
- auto stats (GenerateStats ());
68
-
69
- if (stats)
70
- allStats->Set (Endpoint::GetLocalEndpoint ()->GetName (), stats);
71
-
72
- {
73
- boost::mutex::scoped_lock lock (m_Mutex);
74
-
75
- for (auto & endpointStats : m_SecondaryStats) {
76
- allStats->Set (endpointStats.first , endpointStats.second );
77
- }
78
- }
68
+ auto allStats (GenerateStats ());
79
69
80
70
if (!allStats->GetLength ())
81
71
return ;
@@ -97,8 +87,11 @@ void StatsReporter::ReportStats()
97
87
}
98
88
}
99
89
90
+ static const String l_StatsReporterStatsFunctionName = " StatsReporter" ;
91
+
100
92
Dictionary::Ptr StatsReporter::GenerateStats ()
101
93
{
94
+ auto allStats (new Dictionary);
102
95
Dictionary::Ptr statsFunctions = ScriptGlobal::Get (" StatsFunctions" , &Empty);
103
96
104
97
if (statsFunctions) {
@@ -109,14 +102,24 @@ Dictionary::Ptr StatsReporter::GenerateStats()
109
102
ObjectLock olock (statsFunctions);
110
103
111
104
for (const Dictionary::Pair &kv : statsFunctions) {
112
- ((Function::Ptr ) kv.second )->Invoke ({status, perfdata});
105
+ if (kv.first != l_StatsReporterStatsFunctionName) {
106
+ ((Function::Ptr ) kv.second )->Invoke ({status, perfdata});
107
+ }
113
108
}
114
109
}
115
110
116
- return status;
111
+ allStats->Set (Endpoint::GetLocalEndpoint ()->GetName (), status);
112
+ }
113
+
114
+ {
115
+ boost::mutex::scoped_lock lock (m_Mutex);
116
+
117
+ for (auto & endpointStats : m_SecondaryStats) {
118
+ allStats->Set (endpointStats.first , endpointStats.second );
119
+ }
117
120
}
118
121
119
- return nullptr ;
122
+ return allStats ;
120
123
}
121
124
122
125
Value StatsReporter::ClusterStatsAPIHandler (const MessageOrigin::Ptr & origin, const Dictionary::Ptr & params)
@@ -160,3 +163,8 @@ void StatsReporter::ClusterStatsHandler(const String& endpoint, const Dictionary
160
163
boost::mutex::scoped_lock lock (m_Mutex);
161
164
m_SecondaryStats[endpoint] = stats;
162
165
}
166
+
167
+ void StatsReporter::StatsFunc (const Dictionary::Ptr & status, const Array::Ptr & perfdata)
168
+ {
169
+ status->Set (" cluster" , m_Instance.GenerateStats ());
170
+ }
0 commit comments