定义
connPoolStatsThe command
connPoolStatsreturns information regarding the open outgoing connections from the current database instance to other members of the sharded cluster or replica set.要运行
connPoolStats,请使用db.runCommand( { <command> } )方法。注意
connPoolStatsonly returns meaningful results formongosinstances and formongodinstances in sharded clusters.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.runCommand( { connPoolStats: 1 } )
参数的值(即 1 )不会影响命令的输出。
行为
connPoolStats 在其输出中包含聚合统计信息:
The
hostsfield displays the information aggregated by host.The
poolsfield displays the information aggregated by pool.
注意
To avoid interference with any running operations, connPoolStats does not take any locks. As such, the counts may change slightly as connPoolStats gathers information, resulting in slight differences between the hosts and pools connection counts.
例子
以下操作使用 方法在分片集群的db.runCommand()connPoolStats mongos上运行 命令。分片集群有2 个分片,每个分片都有一个单节点副本集和一个配置服务器副本集。mongos 在具有4 核心的机器上运行。
db.runCommand( { "connPoolStats" : 1 } )
该命令返回以下形式的输出:
注意
The connPoolStats output varies depending on the deployment and the member against which you run connPoolStats among other factors.
{ "numClientConnections" : <num>, "numAScopedConnections" : <num>, "totalInUse" : <num>, "totalAvailable" : <num>, "totalLeased" : <num>, "totalCreated" : <num>, "totalRefreshing" : <num>, "replicaSetMatchingStrategy" : <string>, "acquisitionWaitTimes" : { // Added in MongoDB 6.3 "(-inf, 0ms)" : { "count" : <num> }, "[0ms, 50ms)" : { "count" : <num> }, "[50ms, 100ms)" : { "count" : <num> }, "[100ms, 150ms)" : { "count" : <num> }, "[150ms, 200ms)" : { "count" : <num> }, "[200ms, 250ms)" : { "count" : <num> }, "[250ms, 300ms)" : { "count" : <num> }, "[300ms, 350ms)" : { "count" : <num> }, "[350ms, 400ms)" : { "count" : <num> }, "[400ms, 450ms)" : { "count" : <num> }, "[450ms, 500ms)" : { "count" : <num> }, "[500ms, 550ms)" : { "count" : <num> }, "[550ms, 600ms)" : { "count" : <num> }, "[600ms, 650ms)" : { "count" : <num> }, "[650ms, 700ms)" : { "count" : <num> }, "[700ms, 750ms)" : { "count" : <num> }, "[750ms, 800ms)" : { "count" : <num> }, "[800ms, 850ms)" : { "count" : <num> }, "[850ms, 900ms)" : { "count" : <num> }, "[900ms, 950ms)" : { "count" : <num> }, "[950ms, 1000ms)" : { "count" : <num> }, "[1000ms, inf)" : { "count" : <num> }, "totalCount" : <num> }, "pools" : { "NetworkInterfaceTL-TaskExecutorPool-0" : { "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, }, "NetworkInterfaceTL-TaskExecutorPool-1" : { "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 } }, "NetworkInterfaceTL-TaskExecutorPool-2" : { "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 } }, "NetworkInterfaceTL-TaskExecutorPool-3" : { "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 } }, "NetworkInterfaceTL-ShardRegistry" : { "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "cfg2.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "cfg3.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "shard1.example.net:27018" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "shard2.example.net:27018" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 } }, "global" : { "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "cfg3.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "cfg2.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "shard2.example.net:27018" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "shard1.example.net:27018" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 } } }, "hosts" : { "cfg3.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "cfg1.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "cfg2.example.net:27019" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "shard2.example.net:27018" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "shard1.example.net:27018" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 } }, "replicaSets" : { "csRS" : { "hosts" : [ { "addr" : "cfg1.example.net:27019", "ok" : <bool>, "ismaster" : <bool>, "hidden" : <bool>, "secondary" : <bool>, "pingTimeMillis" : <num> }, { "addr" : "cfg2.example.net:27019", "ok" : <bool>, "ismaster" : <bool>, "hidden" : <bool>, "secondary" : <bool>, "pingTimeMillis" : <num> }, { "addr" : "cfg3.example.net:27019", "ok" : <bool>, "ismaster" : <bool>, "hidden" : <bool>, "secondary" : <bool>, "pingTimeMillis" : <num> } ] }, "shardB" : { "hosts" : [ { "addr" : "shard2.example.net:27018", "ok" : <bool>, "ismaster" : <bool>, "hidden" : <bool>, "secondary" : <bool>, "pingTimeMillis" : <num> } ] }, "shardA" : { "hosts" : [ { "addr" : "shard1.example.net:27018", "ok" : <bool>, "ismaster" : <bool>, "hidden" : <bool>, "secondary" : <bool>, "pingTimeMillis" : <num> } ] } }, "ok" : 1, "$clusterTime" : { "clusterTime" : <timestamp>, "signature" : <document> }, "operationTime" : <timestamp> }
输出
connPoolStats.totalAvailable报告从当前
mongod/mongos实例到分片集群或副本集其他成员的可用传出连接总数。
connPoolStats.totalCreated报告当前
mongod/mongos实例曾向分片集群或副本集的其他成员创建的传出连接总数。
connPoolStats.replicaSetMatchingStrategy版本 5.0 中的新增功能。
在
mongos实例上,此值报告该实例用于确定其连接池到副本集中节点的最小大小限制的策略。在
mongod实例上,此值报告该实例用于确定其与其他副本集中的节点的连接池的最小大小限制的策略。可以使用
mongosmongodShardingTaskExecutorPoolReplicaSetMatching参数设置针对 和 的策略。注意
If the
ShardingTaskExecutorPoolReplicaSetMatchingis set to"automatic", thereplicaSetMatchingStrategystill describes the actual policy being used, not"automatic". To find the value of theShardingTaskExecutorPoolReplicaSetMatching, usegetParameterwhich returns the value of the server parameter:db.adminCommand( { getParameter : 1, "ShardingTaskExecutorPoolReplicaSetMatching" : 1 } )
connPoolStats.acquisitionWaitTimes6.3版本新增。
文档报告一个直方图,其中包含从
mongos到mongod获取连接的请求的等待时间:该文档包含以毫秒为单位的时间范围以及每个范围内的连接请求数。
-inf为负无穷大,(-inf, 0ms)范围内的连接请求不会等待。inf为正无穷大,并且[1000ms, inf)范围内的连接请求等待时间大于或等于 1,000 毫秒。totalCount是所有时间范围内的连接请求总数。
"acquisitionWaitTimes" : { "(-inf, 0ms)" : { "count" : <num> }, "[0ms, 50ms)" : { "count" : <num> }, "[50ms, 100ms)" : { "count" : <num> }, "[100ms, 150ms)" : { "count" : <num> }, "[150ms, 200ms)" : { "count" : <num> }, "[200ms, 250ms)" : { "count" : <num> }, "[250ms, 300ms)" : { "count" : <num> }, "[300ms, 350ms)" : { "count" : <num> }, "[350ms, 400ms)" : { "count" : <num> }, "[400ms, 450ms)" : { "count" : <num> }, "[450ms, 500ms)" : { "count" : <num> }, "[500ms, 550ms)" : { "count" : <num> }, "[550ms, 600ms)" : { "count" : <num> }, "[600ms, 650ms)" : { "count" : <num> }, "[650ms, 700ms)" : { "count" : <num> }, "[700ms, 750ms)" : { "count" : <num> }, "[750ms, 800ms)" : { "count" : <num> }, "[800ms, 850ms)" : { "count" : <num> }, "[850ms, 900ms)" : { "count" : <num> }, "[900ms, 950ms)" : { "count" : <num> }, "[950ms, 1000ms)" : { "count" : <num> }, "[1000ms, inf)" : { "count" : <num> }, "totalCount" : <num> }
connPoolStats.numClientConnection报告从当前
mongod/mongos实例到分片集群或副本集其他成员的活动和存储的传出同步连接的数量。These connections are a part of a pool that is a subset of the data reported by
totalAvailable,totalCreated, andtotalInUse.
connPoolStats.numAScopedConnection报告从当前 /
mongos实例到分mongod片集群 或 副本集 其他成员的活动和已存储传出 范围同步 连接的数量。These connections are a part of a pool that is a subset of the data reported by
totalAvailable,totalCreated, andtotalInUse.
connPoolStats.pools报告按连接池分组的连接统计信息(正在使用/可用/已创建/刷新)。
mongod或mongos有两个不同的传出连接池系列:基于 DBClient 的池(“写入路径”)和
基于 NetworkInterfaceTL 的池(“读取路径”)。
对于每个池,该命令都会返回一个类似于以下内容的文档:
{ "poolInUse" : <num>, "poolAvailable" : <num>, "poolLeased" : <num>, "poolCreated" : <num>, "poolRefreshing" : <num>, "acquisitionWaitTimes" : <document>, // Added in MongoDB 6.3 "[host1]" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, "[host2]" : { "inUse" : <num>, "available" : <num>, "leased" : <num>, "created" : <num>, "refreshing" : <num>, "acquisitionWaitTimes" : <document> // Added in MongoDB 6.3 }, ... } 注意
If there are no connections (in use/available/created/refreshing) for a particular pool, the
connPoolStatsdoes not return statistics for that pool.connPoolStats.pools.NetworkInterfaceTL-TaskExecutorPool-[n]显示与 TaskExecutor 池相关的连接统计信息。 通常,每个内核有一个 TaskExecutorPool,例如
pools.NetworkInterfaceTL-TaskExecutorPool-0...pools.NetworkInterfaceTL-TaskExecutorPool-7表示 8 核处理器。
connPoolStats.pools.NetworkInterfaceTL-Replication如果对副本集的成员运行该命令,则可用。
显示当前
mongod实例与副本集其他成员之间的连接池统计信息。
connPoolStats.pools.[pool].acquisitionWaitTimes6.3版本新增。
Reports the wait times for requests to acquire a connection from
mongostomongod. For details, seeconnPoolStats.acquisitionWaitTimes.
connPoolStats.hosts报告按主机分组的连接统计信息(正在使用/可用/已创建/正在刷新)。
包含文档,这些文档表示当前
mongod/mongos实例与分片集群或副本集的每个成员之间的连接报告。connPoolStats.hosts.[host].leased报告从池中借用并预期返回的主机的连接总数。 这些连接可能不会在租约期间保持活动状态,因此被排除在相关指标之外。 这些连接在租约期间不可用。
connPoolStats.hosts.[host].acquisitionWaitTimes6.3版本新增。
Reports the wait times for requests to acquire a connection from
mongostomongod. For details, seeconnPoolStats.acquisitionWaitTimes.
connPoolStats.replicaSets包含表示与连接到当前 /
mongod的每个副本集相关的信息报告的 文档mongos。connPoolStats.replicaSets.[replicaSets].hosts这些值派生自副本集状态值。
connPoolStats.replicaSets.[replicaSet].hosts[n].addr以
[hostname]:[port]格式报告副本集节点的地址。
connPoolStats.replicaSets.[replicaSet].hosts[n].ismasterReports
trueif thishostis the primary member of the replica set.
connPoolStats.replicaSets.[replicaSet].hosts[n].hiddenReports
trueif thishostis a hidden member of the replica set.
connPoolStats.replicaSets.[replicaSet].hosts[n].secondaryReports
trueif thishostis a secondary member of the replica set.
connPoolStats.replicaSets.[replicaSet].hosts[n].pingTimeMillisReports the ping time in milliseconds from the
mongosormongodto thishost.
connPoolStats.replicaSets.[replicaSet].hosts[n].tags如果该集合的该成员配置了标签,则报告
members[n].tags。
有关 ok 状态字段、operationTime 字段和 $clusterTime 字段的详情,另请参阅响应。