Docs HomeMongoDB Manual

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)mirroredReads读取文档。(从版本4.4开始提供

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

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输出