On this page本页内容
profile
Changed in version 5.0.在版本5.0中更改。
For a 对于mongod
instance, the command enables, disables, or configures the Database Profiler. mongod
实例,该命令启用、禁用或配置数据库探查器。The profiler captures and records data on the performance of write operations, cursors, and database commands on a running 探查器捕获并记录有关正在运行的mongod
instance. mongod
实例上写操作、游标和数据库命令的性能的数据。If the profiler is disabled, the command configures how slow operations are logged to the diagnostic log.如果禁用探查器,则该命令将配置将操作记录到诊断日志的速度。
On 在mongod
, if the database profiler level is 1
or 2
(i.e. the database profiler is enabled), the slowms, sampleRate, and filter affect the behavior of both the profiler and the diagnostic log
.mongod
上,如果数据库探查器级别为1
或2
(即启用了数据库探查器),则slowms、sampleRate和filter会影响探查器和诊断日志的行为。
If the database profiler level is 如果数据库探查器级别为0
(i.e. database profiler is disabled), the slowms, sampleRate, and filter affect only the diagnostic log.0
(即禁用数据库探查器),则slowms、sampleRate和筛选器仅影响诊断日志。
Starting in MongoDB 4.0, for a 从MongoDB 4.0开始,对于mongos
instance, the command only configures how operations get written to the diagnostic log. mongos
实例,该命令只配置如何将操作写入诊断日志。You cannot enable the Database Profiler on a 您不能在mongos
instance because mongos
does not have any collections that the profiler can write to.mongos
实例上启用数据库探查器,因为mongos
没有探查器可以写入的任何集合。
Starting in MongoDB 5.0 (also available starting in 4.4.2, 4.2.12, and 4.0.22), changes made to the database profiler 从MongoDB 5.0开始(也可从4.4.2、4.2.12和4.0.22开始),使用level
, slowms
, sampleRate
, or filter
using the profile
command or db.setProfilingLevel()
wrapper method are recorded in the log file
.profile
命令或dbsetProfileLevel()
包装器方法对数据库探查器level
、slowms
、sampleRate
或filter
所做的更改将记录在日志文件中。
On 在mongos
, you can set profile
level to:mongos
上,您可以将配置文件级别设置为:
0
to set the slowms
, sampleRate
, and filter
for the diagnostic log;0
设置诊断日志的slowms
、sampleRate
和filter
;-1
The profiler is off by default.默认情况下,探查器处于关闭状态。
Profiling can impact performance and shares settings with the system log. 分析可能会影响性能并与系统日志共享设置。Carefully consider any performance and security implications before configuring and enabling the profiler on a production deployment.在生产部署上配置和启用探查器之前,请仔细考虑任何性能和安全问题。
See Profiler Overhead for more information on potential performance degradation.有关潜在性能降级的更多信息,请参阅探查器开销。
The profile
command has the following syntax:profile
命令具有以下语法:
{ profile: <level>, slowms: <threshold>, sampleRate: <rate>, filter: <filter expression> }
profile | int |
| ||||||||
slowms | int |
| ||||||||
sampleRate | double |
sampleRate accepts values between 0 and 1, inclusive.sampleRate 接受介于0和1之间的值(包括0和1)。
| ||||||||
filter | object |
{ <field1>: <expression1>, ... }
|
The db.getProfilingStatus()
and db.setProfilingLevel()
shell methods provide wrappers around the profile
command.db.getProfilingStatus()
和db.setProfilingLevel()
shell方法为profile
命令提供包装器。
The profile
command obtains a write lock on the affected database while enabling or disabling the profiler. profile
命令在启用或禁用探查器时获取受影响数据库的写入锁定。This is typically a short operation. 这通常是一个短操作。The lock blocks other operations until the 锁将阻止其他操作,直到profile
command has completed.profile
命令完成。
Starting in MongoDB 4.4.2, when connected to a sharded cluster through 从MongoDB 4.4.2开始,当通过mongos
, you can run the profile
command against any database. mongos
连接到分片集群时,可以对任何数据库运行profile
命令。In previous versions of MongoDB, when connected through 在MongoDB的早期版本中,当通过mongos
, you can only run the profile
command against the admin
database.mongos
连接时,您只能对admin
数据库运行profile
命令。