db.serverStatus()

On this page本页内容

db.serverStatus()

Returns a document that provides an overview of the database process's state.返回提供数据库进程状态概述的文档

This command provides a wrapper around the database command serverStatus.此命令提供数据库命令serverStatus的包装。

Behavior行为

By default, db.serverStatus() excludes in its output:默认情况下,db.serverStatus()在其输出中排除:

  • some content in the repl document.repl文档中的一些内容。
  • mirroredReads镜像读取 document. 文件(Available starting in version 4.4)从4.4版开始提供

To include fields that are excluded by default, specify the top-level field and set it to 1 in the command. 要包括默认情况下排除的字段,请指定顶级字段并在命令中将其设置为1To exclude fields that are included by default, specify the top-level field and set to 0 in the command.要排除默认情况下包含的字段,请指定顶级字段并在命令中设置为0

For example, the following operation suppresses the repl, metrics and locks information in the output.例如,以下操作抑制输出中的replmetricslocks信息。

db.serverStatus( { repl: 0,  metrics: 0, locks: 0 } )

The following example includes all repl information in the output:以下示例包括输出中的所有repl信息:

db.serverStatus( { repl: 1 } )

Initialization初始化

The statistics reported by db.serverStatus() are reset when the mongod server is restarted. mongod服务器重新启动时,db.serverStatus()报告的统计信息将被重置。The db.serverStatus() command does not report some statistics until they have been initialized by server events.db.serverStatus()命令不会报告某些统计信息,直到它们被服务器事件初始化。

For example, after restarting the mongod server, db.serverStatus() won't return any values for findAndModify.例如,在重新启动mongod服务器后,db.serverStatus()不会返回findAndModify的任何值。

db.serverStatus().metrics.commands.findAndModify
// No results returned

After you run an update query, subsequent calls to db.serverStatus() display the expected metrics.运行更新查询后,对db.serverStatus()的后续调用将显示预期的指标。

{
   "arrayFilters" : NumberLong(0),
   "failed" : NumberLong(0),
   "pipeline" : NumberLong(0),
   "total" : NumberLong(1)
}
Note注意

The db.serverStatus() method returns an error if a specific object is queried before the counters have begun to increment.如果在计数器开始递增之前查询了特定对象,db.serverStatus()方法将返回一个错误。

If there haven't been any document updates yet:如果还没有任何文档更新:

db.serverStatus().metrics.commands.update.pipeline

Returns:退货:

TypeError: db.serverStatus(...).metrics.commands.update is undefined :
@(shell):1:1

Include 包括mirroredReads

By default, the mirroredReads information (available starting in version 4.4) is not included in the output. 默认情况下,输出中不包含mirroredReads信息(从4.4版开始可用)。To return mirroredReads information, you must explicitly specify the inclusion:要返回mirroredReads信息,必须明确指定包含:

db.serverStatus( { mirroredReads: 1 } )

Include 包括latchAnalysis

By default, the latchAnalysis information (available starting in version 4.4) is not included in the output. 默认情况下,输出中不包含latchAnalysis信息(从4.4版开始可用)。To return latchAnalysis information, you must explicitly specify the inclusion:要返回latchAnalysis信息,必须明确指定包含:

db.serverStatus( { latchAnalysis: 1 } )

Output输出

See serverStatus Output for complete documentation of the output of this function.有关此函数输出的完整文档,请参阅serverStatus输出

←  db.serverCmdLineOpts()db.setLogLevel() →