Skip to content

Commit 0140110

Browse files
committed
Feat[mqb]: Add broker stats to stat log
This commit adds the # of clients and queues to the broker's stat log. These values can be derived from existing stats with some legwork; logging them in one line just makes it easier. Note: These metrics show the number of connected clients and opened queues. If a queue exists in storage but has no clients, it does not count. Signed-off-by: Christopher Beard <[email protected]>
1 parent 3f51a52 commit 0140110

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/groups/mqb/mqbstat/mqbstat_brokerstats.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ BrokerStatsUtil::initializeStatContext(int historySize,
115115
config.isTable(true)
116116
.defaultHistorySize(historySize)
117117
.statValueAllocator(allocator)
118-
.storeExpiredSubcontextValues(true)
119118
.value("queue_count")
120119
.value("client_count");
121120

@@ -129,5 +128,41 @@ BrokerStatsUtil::initializeStatContext(int historySize,
129128
return statContext;
130129
}
131130

131+
void BrokerStatsUtil::initializeTableAndTipBroker(
132+
bmqst::Table* table,
133+
bmqst::BasicTableInfoProvider* tip,
134+
int historySize,
135+
bmqst::StatContext* statContext)
136+
{
137+
// Use only one level for now ...
138+
bmqst::StatValue::SnapshotLocation start(0, 0);
139+
bmqst::StatValue::SnapshotLocation end(0, historySize - 1);
140+
141+
// Create table
142+
bmqst::TableSchema& schema = table->schema();
143+
144+
schema.addDefaultIdColumn("id");
145+
schema.addColumn("clients",
146+
BrokerStats::Stat::e_CLIENT_COUNT,
147+
bmqst::StatUtil::value,
148+
start);
149+
schema.addColumn("queues",
150+
BrokerStats::Stat::e_QUEUE_COUNT,
151+
bmqst::StatUtil::value,
152+
start);
153+
154+
// Configure records
155+
bmqst::TableRecords& records = table->records();
156+
records.setContext(statContext);
157+
158+
// Create the tip
159+
tip->setTable(table);
160+
tip->setColumnGroup("");
161+
tip->addColumn("id", "").justifyLeft();
162+
tip->addColumn("clients", "# clients").zeroString("");
163+
tip->addColumn("queues", "# queues").zeroString("");
164+
165+
}
166+
132167
} // close package namespace
133168
} // close enterprise namespace

src/groups/mqb/mqbstat/mqbstat_brokerstats.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
// MQB
3131

3232
// BMQ
33+
#include <bmqst_basictableinfoprovider.h>
3334
#include <bmqst_statcontext.h>
35+
#include <bmqst_table.h>
3436
#include <bmqt_uri.h>
3537

3638
// BDE
39+
#include <ball_log.h>
3740
#include <bsl_memory.h>
3841
#include <bsl_string.h>
3942
#include <bslma_allocator.h>
@@ -151,6 +154,14 @@ struct BrokerStatsUtil {
151154
/// specified `allocator` for all stat context and stat values.
152155
static bsl::shared_ptr<bmqst::StatContext>
153156
initializeStatContext(int historySize, bslma::Allocator* allocator);
157+
158+
/// Load in the specified `table` and `tip` the objects to print the
159+
/// specified `statContext` for the specified `historySize`.
160+
static void
161+
initializeTableAndTipBroker(bmqst::Table* table,
162+
bmqst::BasicTableInfoProvider* tip,
163+
int historySize,
164+
bmqst::StatContext* statContext);
154165
};
155166

156167
// ============================================================================

src/groups/mqb/mqbstat/mqbstat_printer.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <mqbscm_version.h>
2020
// MQB
21+
#include <mqbstat_brokerstats.h>
2122
#include <mqbstat_queuestats.h>
2223

2324
#include <bmqio_statchannelfactory.h>
@@ -90,6 +91,12 @@ void Printer::initializeTablesAndTips()
9091
historySize,
9192
context->d_statContext_p);
9293

94+
context = d_contexts["broker"].get();
95+
BrokerStatsUtil::initializeTableAndTipBroker(&context->d_table,
96+
&context->d_tip,
97+
historySize,
98+
context->d_statContext_p);
99+
93100
context = d_contexts["clients"].get();
94101
QueueStatsUtil::initializeTableAndTipClients(&context->d_table,
95102
&context->d_tip,
@@ -214,11 +221,19 @@ void Printer::stop()
214221
void Printer::printStats(bsl::ostream& stream)
215222
{
216223
// This must execute in the 'snapshot' thread
224+
Context* context;
225+
226+
// BROKER
227+
stream << "\n"
228+
<< ":::::::::: :::::::::: BROKER >>";
229+
context = d_contexts["broker"].get();
230+
context->d_table.records().update();
231+
bmqst::TableUtil::printTable(stream, context->d_tip);
217232

218233
// DOMAINQUEUES
219234
stream << "\n"
220235
<< ":::::::::: :::::::::: DOMAINQUEUES >>";
221-
Context* context = d_contexts["domainQueues"].get();
236+
context = d_contexts["domainQueues"].get();
222237
context->d_table.records().update();
223238
bmqst::TableUtil::printTable(stream, context->d_tip);
224239

0 commit comments

Comments
 (0)