Skip to content

Commit b5c9096

Browse files
committed
MB-59260: BP:58199: Add max_[user/system]_connections to stats
Add the max setting for user and system connections to prometheus to allow for monitoring the current count with the max limit. Change-Id: Ia962e6445dd05c79e1fbae537df5548c06de780c Reviewed-on: https://review.couchbase.org/c/kv_engine/+/199509 Well-Formed: Restriction Checker Reviewed-by: Paolo Cocchi <[email protected]> Tested-by: Trond Norbye <[email protected]>
1 parent 3937e0b commit b5c9096

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

daemon/stats.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ static void server_global_stats(const StatCollector& collector) {
4141
collector.addStat(Key::memcached_version, MEMCACHED_VERSION);
4242

4343
collector.addStat(Key::daemon_connections, ServerSocket::getNumInstances());
44-
collector.addStat(Key::curr_connections,
45-
stats.curr_conns.load(std::memory_order_relaxed));
46-
collector.addStat(Key::system_connections,
47-
stats.system_conns.load(std::memory_order_relaxed));
44+
const auto curr = stats.curr_conns.load();
45+
const auto sys = stats.system_conns.load();
46+
collector.addStat(Key::curr_connections, curr);
47+
collector.addStat(Key::system_connections, sys);
48+
collector.addStat(Key::user_connections, curr>sys ? curr - sys : 0);
4849
collector.addStat(Key::total_connections, stats.total_conns);
4950
collector.addStat(Key::connection_structures, stats.conn_structs);
51+
collector.addStat(Key::max_user_connections,
52+
Settings::instance().getMaxUserConnections());
53+
collector.addStat(Key::max_system_connections,
54+
Settings::instance().getSystemConnections());
5055

5156
auto pool_size = Settings::instance().getFreeConnectionPoolSize();
5257
if (pool_size != 0) {

include/statistics/stats.def.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ STAT(memcached_version, , none, , ) // version string
471471
STAT(daemon_connections, , count, , )
472472
STAT(curr_connections, , count, , )
473473
STAT(system_connections, , count, , )
474+
STAT(user_connections, , count, , )
474475
STAT(total_connections, , count, , ) // total since start/reset
475476
STAT(connection_structures, , count, , )
477+
STAT(max_user_connections, , count, , )
478+
STAT(max_system_connections, , count, , )
476479
STAT(connection_recycle_high_watermark, , none, , )
477480

478481
// Amount of memory allocated by the daemon.

tests/testapp/testapp_stats.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ TEST_P(StatsTest, MB37147_TestEWBReturnFromStat) {
299299
sequence);
300300
auto stats = connection.stats("vbucket");
301301
EXPECT_FALSE(stats.empty());
302+
connection.disableEwouldBlockEngine();
302303
});
303304
}
304305

@@ -540,3 +541,17 @@ TEST_P(StatsTest, TestClocksStats) {
540541
<< value << "'";
541542
}
542543
}
544+
545+
/// The stats should contain max user and system connections to allow
546+
/// for alerting by monitoring the current levels with the max
547+
TEST_P(StatsTest, MB59260) {
548+
nlohmann::json stats;
549+
adminConnection->executeInBucket(
550+
bucketName, [&stats](auto& conn) { stats = conn.stats(""); });
551+
ASSERT_TRUE(stats.contains("max_system_connections"));
552+
ASSERT_TRUE(stats.contains("max_user_connections"));
553+
const auto max_system = Testapp::MAX_CONNECTIONS / 4;
554+
const auto max_user = Testapp::MAX_CONNECTIONS - max_system;
555+
EXPECT_EQ(max_system, stats["max_system_connections"]);
556+
EXPECT_EQ(max_user, stats["max_user_connections"]);
557+
}

0 commit comments

Comments
 (0)