- Reference >
- Database Commands >
- Diagnostic Commands >
- profile
profile¶
On this page
Definition¶
-
profile
¶ Changed in version 4.0: The command can be run on
mongos
withprofile
level:0
to set theslowms
andsampleRate
for the system log; i.e. you cannot enable the profiler on amongos
.-1
to read the current settings.
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 runningmongod
instance. If the profiler is disabled, the command sets theslowms
andsampleRate
for logging slow operations to the diagnostic log.For
mongos
instance, the command sets theslowms
andsampleRate
configuration settings, which configure how operations get written to the diagnostic log.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:Field Type Description profile
int Configures the profiler level. The following profiler levels are available:
Level Description 0
The profiler is off and does not collect any data. This is the default profiler level. 1
The profiler collects data for operations that take longer than the value of slowms
.2
The profiler collects data for all operations. Since profiling is not available on
mongos
, theprofile
command cannot be used to set the profiling level to a value other than0
on amongos
instance.slowms
int Optional. Default: 100
The slow operation time threshold, in milliseconds. Operations that run for longer than this threshold are considered slow.
When
logLevel
is set to0
, MongoDB records slow operations to the diagnostic log at a rate determined byslowOpSampleRate
. Starting in MongoDB 4.2, the secondaries of replica sets log all oplog entry messages that take longer than the slow operation threshold to apply regardless of the sample rate.At higher
logLevel
settings, all operations appear in the diagnostic log regardless of their latency with the following exception: the logging of slow oplog entry messages by the secondaries. The secondaries log only the slow oplog entries; increasing thelogLevel
does not log all oplog entries.Note
This argument affects the same setting as the configuration option
slowOpThresholdMs
.sampleRate
double Optional. Default: 1.0
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
slowOpSampleRate
and does not affect the slow oplog entry log messages on secondaries (available starting in MongoDB 4.2).New in version 3.6.
The db.getProfilingStatus()
and
db.setProfilingLevel()
shell methods provide wrappers around the profile
command.