重要
mongosh 方法
This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.
有关数据库命令,请参阅 collStats 命令返回的 latencyStats 字段。
如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
定义
db.collection.latencyStats(options)db.collection.latencyStats()returns latency statistics for a given collection. It is a wrapper around$collStats.此方法的形式为:
db.collection.latencyStats( { histograms: <boolean> } ) The
histogramsargument is an optional boolean. Ifhistograms: truethenlatencyStats()adds latency histograms to the return document.
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
输出
latencyStats() returns a document containing a field latencyStats, containing the following fields:
字段名称 | 说明 |
|---|---|
| 读取请求的延迟统计信息。 |
| 写入请求的延迟统计数据。 |
| 数据库命令的延迟统计信息。 |
| 数据库事务的延迟统计信息。 |
其中每个字段都包含一个包含以下字段的嵌入文档:
字段名称 | 说明 | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 一个 64 位整数,以微秒为单位表示总组合延迟。 | |||||||||||||
| 一个 64 位整数,表示自启动以来对集合执行的操作总数。 | |||||||||||||
| 嵌入式文档大量,每个文档代表一个延迟范围。 每个文档的覆盖范围是前一个文档范围的两倍。 对于介于2048微秒到大约1秒之间的较低值,直方图包括半步。 此字段仅在给定 每个文档都包含以下字段:
例如,如果 这表明有 [1]:
|
| [1] |
|
示例
You can run latencyStats() in mongosh as follows:
db.data.latencyStats( { histograms: true } ).pretty()
latencyStats() 返回如下文档:
{ "ns" : "test.data", "localTime" : ISODate("2016-11-01T21:56:28.962Z"), "latencyStats" : { "reads" : { "histogram" : [ { "micros" : Long(16), "count" : Long(6) }, { "micros" : Long(512), "count" : Long(1) } ], "latency" : Long(747), "ops" : Long(7) }, "writes" : { "histogram" : [ { "micros" : Long(64), "count" : Long(1) }, { "micros" : Long(24576), "count" : Long(1) } ], "latency" : Long(26845), "ops" : Long(2) }, "commands" : { "histogram" : [ ], "latency" : Long(0), "ops" : Long(0) } } }