Buy Percona ServicesBuy Now!

Configuring MongoDB for Monitoring in Query Analytics

In QAN (Query Analytics), you can monitor MongoDB metrics and MongoDB queries with the mongodb:metrics or mongodb:queries monitoring services accordingly. Run the pmm-admin add command to use these monitoring services (for more information, see Adding monitoring services).

Setting Up the Essential Permissions

For mongodb:metrics and mongodb:queries monitoring services to be able work in QAN, you need to set up the mongodb_exporter user. This user should be assigned the clusterMonitor role for the admin database and the read role for the local database.

The following example that you can run in the MongoDB shell, adds the mongodb_exporter user and assigns the appropriate roles.

db.getSiblingDB("admin").createUser({
    user: "mongodb_exporter",
    pwd: "s3cR#tpa$$worD",
    roles: [
        { role: "clusterMonitor", db: "admin" },
        { role: "read", db: "local" }
    ]
})

Then, you need to pass the user name and password in the value of the --uri option when adding the mongodb:metrics monitoring service in the pmm-admin add command:

Run this command as root or by using the sudo command.

See also

Adding a mongodb:metrics monitoring service
Adding MongoDB metrics service

Enabling Profiling

For MongoDB to work correctly with QAN (Query Analytics), you need to enable profiling in your mongod configuration. When started without profiling enabled, QAN displays the following warning:

Note

A warning message is displayed when profiling is not enabled

It is required that profiling of the monitored MongoDB databases be enabled.

Note that profiling is not enabled by default because it may reduce the performance of your MongoDB server.

Enabling Profiling on Command Line

You can enable profiling from command line when you start the mongod server. This command is useful if you start mongod manually.

Run this command as root or by using the sudo command

$ mongod --dbpath=DATABASEDIR --profile 1 --slowms 200 --rateLimit 100

Note that you need to specify a path to an existing directory that stores database files with the --dpbath. When the --profile option is set to 1, mongod only collects the profiling data for slow operations. The --slowms option sets the minimum time for a slow operation. In the given example, any operation which takes longer than 200 milliseconds is a slow operation.

The --rateLimit option, which is available if you use Percona Server for MongoDB instead of MongoDB, refers to the number of queries that the MongoDB profiler collects. The lower the rate limit, the less impact on the performance. However, the accuracy of the collected information decreases as well.

See also

--rateLimit in Percona Server for MongoDB documentation
https://www.percona.com/doc/percona-server-for-mongodb/LATEST/rate-limit.html

Enabling Profiling in the Configuration File

If you run mongod as a service, you need to use the configuration file which by default is /etc/mongod.conf.

In this file, you need to locate the operationProfiling: section and add the following settings:

operationProfiling:
   slowOpThresholdMs: 200
   mode: slowOp
   rateLimit: 100

These settings affect mongod in the same way as the command line options described in section Enabling Profiling on Command Line. Note that the configuration file is in the YAML format. In this format the indentation of your lines is important as it defines levels of nesting.

Restart the mongod service to enable the settings.

$ sudo service mongod restart

See also

Enabling Profiling (from MongoDB documentation)
https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/
Profiling Mode (from MongoDB documentation)
https://docs.mongodb.com/manual/reference/configuration-options/#operationProfiling.mode
The SlowOpThresholdMd option (from MongoDB documentation)
https://docs.mongodb.com/manual/reference/configuration-options/#operationProfiling.slowOpThresholdMs
Profiler Overhead (from MongoDB documentation)
https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/#profiler-overhead
Profiling Rate Limit (from the documentation for Percona Server for MongoDB)
https://www.percona.com/doc/percona-server-for-mongodb/LATEST/rate-limit.html
Visit Percona Store


General Inquiries

For general inquiries, please send us your question and someone will contact you.