Performance analysis tools
Built-in diagnostic utilities
MongoDB offers utilities to help you get performance data:
- mongostat
: Collects statistics on CPU and memory usage with MongoDB processes. - mongotop
: Collects data read/write statistics for each collection.
When calling these utilities, use the connection string with the username and password of the user with the mdbMonitor
role, for example:
mongostat 5 --uri="mongodb://{<name_of_user_with_mdbMonitor_role>}:{<password>}@{<host>}:27018/?authSource=admin"
mongotop 5 --uri="mongodb://{<name_of_user_with_mdbMonitor_role>}:{<password>}@{<host>}:27018/?authSource=admin"
Here, both utilities provide a set of performance data with a polling interval of 5 seconds.
For more information about using monostat
and mongotop
, see the MongoDB documentation
Profiler
MongoDB has a built-in profiler
Warning
The all
value for operationProfiling.mode
and a value close to 0
for operationProfiling.slowOpThreshold
significantly degrade cluster performance.
To view the data collected by the profiler, use the system.profile
collection in each database. Profiler collections are read-only to the user with the mdbMonitor
role. By default, the data is duplicated in the logs.
For more information about configuring the profiler and how to interpret its results, see the MongoDB documentation
Currently running queries
To view queries that do not pertain to the current user, run the db.currentOp()mdbMonitor
role:
db.currentOp()
To view the current user's queries, run the db.currentOp()
query with the true
value to configureownOps
:
db.currentOp({ "$ownOps": true })
Logs
You can find the most detailed information about MongoDB performance in the logs.
- Go to the folder page
and select Managed Service for MongoDB. - Click the cluster name and select the
Logs tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To view the Managed Service for MongoDB logs:
-
View a description of the CLI command to view the logs:
yc managed-mongodb cluster list-logs --help
-
To get all the cluster logs, run the command:
yc managed-mongodb cluster list-logs --id <cluster_ID>
You can get the cluster ID with a list of clusters in the folder.
To view logs, use the listLogs REST API method for the Cluster resource or the ClusterService/ListLogs gRPC API call and provide the cluster ID in the clusterId
request parameter.
You can get the cluster ID with a list of clusters in the folder.