On this page本页内容
profile
¶Changed in version 4.4.2.
For a mongod
instance, the command enables, disables, or configures the Database Profiler. The profiler captures and records data on the performance of write operations, cursors, and database commands on a running mongod
instance. 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
.
If the database profiler level is 0
(i.e. database profiler is disabled), the slowms, sampleRate, and filter affect only the diagnostic log.
(Starting in MongoDB 4.0): For mongos
instance, the command only configures how operations get written to the diagnostic log. You cannot enable the Database Profiler on a mongos
instance because mongos
does not have any collections that the profiler can write to.
On mongos
, you can set profile
level to:
0
to set the slowms
, sampleRate
, and filter
for the diagnostic log;-1
to read the current settings.The profiler is off by default.
Important
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 |
int | Configures the profiler level. The following profiler levels are available:
Since profiling is not available on | ||||||||
slowms |
int |
The slow operation time threshold, in milliseconds. Operations that run for longer than this threshold are considered slow. When At higher Note This argument affects the same setting as the configuration option | ||||||||
sampleRate |
double |
The fraction of slow operations that should be profiled or logged.
sampleRate accepts values between 0 and 1, inclusive.Note This argument affects the same setting as the configuration option
| ||||||||
filter |
object | Optional. A filter expression that controls which operations are profiled and logged. The The Note This argument affects the same setting as the configuration option New in version 4.4.2. |
The db.getProfilingStatus()
and db.setProfilingLevel()
shell methods provide wrappers around the profile
command.
The profile
command obtains a write lock on the affected database while enabling or disabling the profiler. This is typically a short operation. The lock blocks other operations until the profile
command has completed.
Starting in MongoDB 4.4.2, when connected to a sharded cluster through mongos
, you can run the profile
command against any database. In previous versions of MongoDB, when connected through mongos
, you can only run the profile
command against the admin
database.
See also参阅