文档菜单
文档首页
/
MongoDB 手册
/ / /

top

本页内容

  • 定义
  • 兼容性
  • 语法
  • 事件字段
  • 示例
  • 了解更多
top

top 是一个管理命令,它返回每个集合的使用统计信息。您可以使用 top 指标来比较您各个集合之间的相对性能。

重要

必须针对 top 命令运行mongod 实例。针对 mongos 实例运行 top 将返回错误。

对于每个集合,top 返回每个事件执行所需的时间(以微秒为单位)以及每个事件执行的count次数。只有重启你的mongod实例后,timecount指标才会重置。

使用可查询加密时,top命令仅返回集合名称。

此命令在以下环境的主机中可用

  • MongoDB Atlas:MongoDB在云中的全托管服务

重要

此命令不支持在无服务器实例中运行。有关更多信息,请参阅不受支持的命令。

针对top 命令对管理员数据库执行:

db.runCommand(
{
top: 1
}
)

top 命令返回以下事件字段的使用统计信息

字段
描述
total
所有 readLockwriteLock 操作的组合。
readLock
使用读锁的操作的使用统计信息。这些操作包括但不限于查询和聚合。
writeLock
使用写锁的操作的使用统计信息。这些操作包括但不限于插入、更新和删除文档。
queries
查询操作的使用统计信息,例如 find。字段 queries.timequeries.count 也会更新 readLock.time 并增加 readLock.count
getmore
getMore 操作的使用统计信息。字段 getmore.timegetmore.count 也会更新 readLock.time 并增加 readLock.count
insert
insert 操作的使用统计。字段 insert.timeinsert.count 也会更新 readLock.time 并增加 readLock.count
update
update 操作的使用统计。字段 update.timeupdate.count 也会更新 readLock.time 并增加 readLock.count
remove
delete 操作的使用统计。字段 remove.timeremove.count 也会更新 readLock.time 并增加 readLock.count
commands

对诸如聚合、索引创建和索引删除等操作的使用统计。根据命令类型,字段 commands.timecommands.count 会更新 writeLock 字段或 readLock 字段。

例如,聚合操作会增加 readLock.timereadLock.count。索引创建会增加 writeLock.timewriteLock.count

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

返回

shardConnPoolStats