diff options
-rw-r--r-- | src/mongo/executor/connection_pool_stats.cpp | 17 | ||||
-rw-r--r-- | src/mongo/executor/connection_pool_stats.h | 13 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/mongo/executor/connection_pool_stats.cpp b/src/mongo/executor/connection_pool_stats.cpp index b1d558bfd8b..31da4d38f96 100644 --- a/src/mongo/executor/connection_pool_stats.cpp +++ b/src/mongo/executor/connection_pool_stats.cpp @@ -57,10 +57,18 @@ ConnectionStatsPer& ConnectionStatsPer::operator+=(const ConnectionStatsPer& oth void ConnectionPoolStats::updateStatsForHost(std::string pool, HostAndPort host, ConnectionStatsPer newStats) { + if (newStats.created == 0) { + // A pool that has never been successfully used does not get listed + return; + } + + // Update stats for this pool + auto& byPool = statsByPool[pool]; + byPool += newStats; + // Update stats for this host. - statsByPool[pool] += newStats; statsByHost[host] += newStats; - statsByPoolHost[pool][host] += newStats; + byPool.statsByHost[host] += newStats; // Update total connection stats. totalInUse += newStats.inUse; @@ -81,7 +89,7 @@ void ConnectionPoolStats::appendToBSON(mongo::BSONObjBuilder& result, bool forFT BSONObjBuilder poolInfo(poolBuilder.subobjStart(pool.first)); auto& poolStats = pool.second; poolInfo.appendNumber("poolInUse", poolStats.inUse); - for (const auto& host : statsByPoolHost[pool.first]) { + for (const auto& host : poolStats.statsByHost) { auto hostStats = host.second; poolInfo.appendNumber(host.first.toString(), hostStats.inUse); } @@ -99,7 +107,8 @@ void ConnectionPoolStats::appendToBSON(mongo::BSONObjBuilder& result, bool forFT poolInfo.appendNumber("poolAvailable", poolStats.available); poolInfo.appendNumber("poolCreated", poolStats.created); poolInfo.appendNumber("poolRefreshing", poolStats.refreshing); - for (const auto& host : statsByPoolHost[pool.first]) { + + for (const auto& host : poolStats.statsByHost) { BSONObjBuilder hostInfo(poolInfo.subobjStart(host.first.toString())); auto& hostStats = host.second; hostInfo.appendNumber("inUse", hostStats.inUse); diff --git a/src/mongo/executor/connection_pool_stats.h b/src/mongo/executor/connection_pool_stats.h index 0e5ec17407a..bfa9a771ac2 100644 --- a/src/mongo/executor/connection_pool_stats.h +++ b/src/mongo/executor/connection_pool_stats.h @@ -67,10 +67,15 @@ struct ConnectionPoolStats { size_t totalCreated = 0u; size_t totalRefreshing = 0u; - stdx::unordered_map<std::string, ConnectionStatsPer> statsByPool; - stdx::unordered_map<HostAndPort, ConnectionStatsPer> statsByHost; - stdx::unordered_map<std::string, stdx::unordered_map<HostAndPort, ConnectionStatsPer>> - statsByPoolHost; + using StatsByHost = std::map<HostAndPort, ConnectionStatsPer>; + + struct PoolStats final : public ConnectionStatsPer { + StatsByHost statsByHost; + }; + using StatsByPool = std::map<std::string, PoolStats>; + + StatsByHost statsByHost; + StatsByPool statsByPool; }; } // namespace executor |