Database Manual / Reference / Database Commands / Diagnostics

top (database command数据库命令)

top

top is an administrative command that returns usage statistics for each collection. You can use top metrics to compare the relative performance of your collections against each other.是一个管理命令,返回每个集合的使用统计信息。您可以使用top指标来比较集合的相对性能。

Important

The top command must be run against a mongod instance. top命令必须针对mongod实例运行。Running top against a mongos instance returns an error.mongos实例运行top会返回错误。

Definition定义

For every collection, top returns the amount of time, in microseconds, that each event takes to execute and a count of how many times each event has executed. 对于每个集合,top返回每个事件执行所需的time量(以微秒为单位)以及每个事件执行的次数countThe time and count metrics reset only after you restart your mongod instance.只有在重新启动mongod实例后,timecount指标才会重置。

Redaction编校

When using Queryable Encryption, the top command only returns the collection name.使用可查询加密时,top命令仅返回集合名称。

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Syntax语法

Issue the top command against the admin database:admin数据库发出top命令:

db.runCommand(
{
top: 1
}
)

Event Fields事件字段

The top command returns usage statistics for the following event fields:top命令返回以下事件字段的使用统计信息:

Field字段Description描述
totalThe combination of all readLock and writeLock operations.所有readLockwriteLock操作的组合。
readLockUsage statistics for operations that use read locks. These operations include but are not limited to queries and aggregations.使用读取锁的操作的使用统计信息。这些操作包括但不限于查询和聚合。
writeLockUsage statistics for operations that use write locks. These operations include but are not limited to inserting, updating, and removing documents.使用写锁的操作的使用统计信息。这些操作包括但不限于插入、更新和删除文档。
queriesUsage statistics for query operations such as find. The queries.time and queries.count fields also update readLock.time and increment readLock.count.查找等find操作的使用统计信息。queries.timequeries.count字段还更新readLock.time并递增readLock.count
getmoreUsage statistics for getMore operations.getMore操作的使用统计信息。
insertUsage statistics for insert operations. The insert.time and insert.count fields also update writeLock.time and increment writeLock.count.insert操作的使用统计信息。insert.timeinsert.count字段还更新writeLock.time并递增writeLock.count
updateUsage statistics for update operations. The update.time and update.count fields also update writeLock.time and increment writeLock.count.update操作的使用统计信息。update.timeupdate.count字段还更新writeLock.time和递增writeLock.count
removeUsage statistics for delete operations. The remove.time and remove.count fields also update writeLock.time and increment writeLock.count.delete操作的使用统计信息。remove.timeremove.count字段还更新writeLock.time并递增writeLock.count
commands

Usage statistics for operations such as aggregations, index creation, and index removal. 聚合、索引创建和索引删除等操作的使用统计信息。Depending on the type of command, the commands.time and commands.count fields update the writeLock fields or the readLock fields.根据命令的类型,commands.timecommands.count字段会更新writeLock字段或readLock字段。

For example, aggregation operations increment readLock.time and readLock.count. Index creation increments writeLock.time and writeLock.count.例如,聚合操作会增加readLock.timereadLock.count。索引创建会增加writeLock.timewriteLock.count

Example示例

The output of the top command resembles the following output:top命令的输出类似于以下输出:

{
"totals" : {
note: "all times in microseconds",
"records.users" : {
"total" : {
"time" : 305277,
"count" : 2825
},
"readLock" : {
"time" : 305264,
"count" : 2824
},
"writeLock" : {
"time" : 13,
"count" : 1
},
"queries" : {
"time" : 305264,
"count" : 2824
},
"getmore" : {
"time" : 0,
"count" : 0
},
"insert" : {
"time" : 0,
"count" : 0
},
"update" : {
"time" : 0,
"count" : 0
},
"remove" : {
"time" : 0,
"count" : 0
},
"commands" : {
"time" : 0,
"count" : 0
}
}
}

Learn More了解更多