对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

connPoolStats(数据库命令)

connPoolStats

命令 connPoolStats 将来自当前数据库实例的有关打开外向连接的信息,返回到分片集群或副本集其他节点。

要运行 connPoolStats,请使用 db.runCommand( { <command> } ) 方法。

注意

connPoolStats仅对分分片的集群中的mongos实例和mongod实例返回有意义的结果。

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

注意

所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。

该命令具有以下语法:

db.runCommand( { connPoolStats: 1 })

参数的值(即 1 )不会影响命令的输出。

connPoolStats 在其输出中包含聚合统计信息:

  • hosts字段显示按托管聚合的信息。

  • pools字段显示按池聚合的信息。

注意

为避免干扰任何运行操作,connPoolStats 不采用任何锁。因此,随着 connPoolStats 收集信息,计数可能会略有变化,导致 hosts 和 pools 的连接计数略有不同。

以下操作使用db.runCommand() 方法在分分片集群的 上运行connPoolStats mongos命令。分片分片集群有2分片,每个分片都有一个单成员副本集和一个配置服务器副本集。 mongos在4核心机器上运行。

db.runCommand( { "connPoolStats" : 1 } )

该命令返回以下形式的输出:

注意

connPoolStats输出会有所不同,具体取决于部署以及运行connPoolStats所针对的成员等因素。

{ "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.totalLeased

报告从池中借用并预期返回的连接总数。 这些连接可能不会在租约期间保持活动状态,因此被排除在相关指标之外。 这些连接在租约期间不可用。

connPoolStats.totalCreated

报告当前mongod / mongos实例曾向分片集群或副本集的其他成员创建的传出连接总数。

connPoolStats.totalInUse

报告从当前mongod / mongos实例到当前正在使用的分片集群或副本集的其他成员的传出连接总数。

connPoolStats.totalRefreshing

报告从当前mongod / mongos实例到当前正在刷新的分片集群或副本集的其他成员的传出连接总数。

connPoolStats.totalWasNeverUsed

报告从当前mongod / mongos实例到分片集群或副本集的其他成员的传出连接总数,这些连接因从未使用过而关闭。

connPoolStats.replicaSetMatchingStrategy

版本 5.0 中的新增功能。

在mongos实例上,此值报告该实例用于确定其连接池到副本集中节点的最小大小限制的策略。

在mongod实例上,此值报告该实例用于确定其与其他副本集中的节点的连接池的最小大小限制的策略。

可以使用 mongosmongodShardingTaskExecutorPoolReplicaSetMatching参数设置针对 和 的策略。

注意

如果ShardingTaskExecutorPoolReplicaSetMatching设立为"automatic" ,则replicaSetMatchingStrategy仍然描述实际使用的策略,而不是"automatic" 。 要查找ShardingTaskExecutorPoolReplicaSetMatching的值,请使用getParameter返回服务器参数的值:

db.adminCommand( { getParameter : 1, "ShardingTaskExecutorPoolReplicaSetMatching" : 1 } )
connPoolStats.acquisitionWaitTimes

6.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实例到分片集群或副本集其他成员的活动和存储的传出同步连接的数量。

这些连接是 totalAvailable、totalCreated 和 totalInUse 报告的数据子集池的一部分。

connPoolStats.numAScopedConnection

报告从当前 /mongos 实例到分mongod 片集群 或 副本集 其他成员的活动和已存储传出 范围同步 连接的数量。

这些连接是 totalAvailable、totalCreated 和 totalInUse 报告的数据子集池的一部分。

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 }, ...}

注意

如果某个数据池没有连接(使用中/可用/已创建/正刷新),connPoolStats 不会返回该数据池的统计数据。

connPoolStats.pools.NetworkInterfaceTL-TaskExecutorPool-[n]

显示与 TaskExecutor 池相关的连接统计信息。 通常,每个内核有一个 TaskExecutorPool,例如 pools.NetworkInterfaceTL-TaskExecutorPool-0 ... pools.NetworkInterfaceTL-TaskExecutorPool-7表示 8 核处理器。

connPoolStats.pools.NetworkInterfaceTL-ShardRegistry

如果对分片集群的成员运行该命令,则可用。

显示当前mongod / mongos实例与分片集群其他成员之间的连接池统计信息。

connPoolStats.pools.NetworkInterfaceTL-Replication

如果对副本集的成员运行该命令,则可用。

显示当前mongod实例与副本集其他成员之间的连接池统计信息。

connPoolStats.pools.global

显示基于 DBClient 的池统计信息。

connPoolStats.pools.[pool].poolWasNeverUsed

显示此连接池中因从未使用而关闭的连接数。

connPoolStats.pools.[pool].acquisitionWaitTimes

6.3版本新增。

报告获取从mongos到mongod的连接的请求的等待时间。 有关详细信息,请参阅connPoolStats.acquisitionWaitTimes 。

connPoolStats.hosts

报告按主机分组的连接统计信息(正在使用/可用/已创建/正在刷新)。

包含文档,这些文档表示当前mongod / mongos实例与分片集群或副本集的每个成员之间的连接报告。

connPoolStats.hosts.[host].available

报告可用于连接到[host]的连接总数。

connPoolStats.hosts.[host].leased

报告从池中借用并预期返回的主机的连接总数。 这些连接可能不会在租约期间保持活动状态,因此被排除在相关指标之外。 这些连接在租约期间不可用。

connPoolStats.hosts.[host].created

报告曾经创建的与[host]的连接数。

connPoolStats.hosts.[host].inUse

报告当前正在使用的与[host]的连接数。

connPoolStats.hosts.[host].wasNeverUsed

报告从host到分片集群或副本集其他成员的传出连接总数,这些连接因从未使用过而被关闭。

connPoolStats.hosts.[host].acquisitionWaitTimes

6.3版本新增。

报告获取从mongos到mongod的连接的请求的等待时间。 有关详细信息,请参阅connPoolStats.acquisitionWaitTimes 。

connPoolStats.replicaSets

包含表示与连接到当前 /mongod 的每个副本集相关的信息报告的 文档mongos 。

connPoolStats.replicaSets.replicaSet

报告连接到当前 / mongod的每个 副本集mongos 。

connPoolStats.replicaSets.[replicaSets].hosts

包含报告 副本集 每个成员的 文档 数组。

这些值派生自副本集状态值。

connPoolStats.replicaSets.[replicaSet].hosts[n].addr

以[hostname]:[port]格式报告副本集节点的地址。

connPoolStats.replicaSets.[replicaSet].hosts[n].ok

在以下情况下报告false :

此字段供内部使用。

connPoolStats.replicaSets.[replicaSet].hosts[n].ismaster

true如果此host 是 副本集 的 主节点 (primary node in the replica set) 节点,则报告 。

connPoolStats.replicaSets.[replicaSet].hosts[n].hidden

如果此 host 是副本集的隐藏节点,则报告 true。

connPoolStats.replicaSets.[replicaSet].hosts[n].secondary

如果此 host 是副本集的次节点,则报告 true。

connPoolStats.replicaSets.[replicaSet].hosts[n].pingTimeMillis

报告从mongos或mongod到此host的网络探测(ping)时间(以毫秒为单位)。

connPoolStats.replicaSets.[replicaSet].hosts[n].tags

如果该集合的该成员配置了标签,则报告members[n].tags 。

有关 ok 状态字段、operationTime 字段和 $clusterTime 字段的详情,另请参阅响应。

host

给本页内容打分