Configuring MongoDB monitoring
The Monitoring Agent for MongoDB requires an instance name. You must manually configure and start the agent instance. The MongoDB agent supports local as well as remote monitoring. Refer the following prerequisites for configuring MongoDB agent for both remote and local monitoring.
Before you begin
- Ensure that the user, who configures the MongoDB agent, has the required roles to collect
data for all attributes.
- To configure the agent on the MongoDB database version 2.4 and version 2.6, the clusterAdmin, readAnyDatabase, and dbAdminAnyDatabase roles must be assigned to the user
- To configure the agent on the MongoDB database version 3.x and 4.x, the clusterMonitor, readAnyDatabase, and dbAdminAnyDatabase roles must be assigned to the user
- Use an existing user or create a user in the admin database. Important: Before you create a user and grant the required roles to the user, make sure to connect to the MongoDB database and change the database to admin database. If the mongod or mongos process is running in the authentication mode, enter the required credentials to connect to MongoDB database.
- Run the following command to connect to the MongoDB database:
mongo IP:port
Where- IP is the IP address of the mongod or mongos process
- port is the port number of the mongod or mongos process
- Change the database to the admin database:
use admin
- Run one of the following commands to add a user in the MongoDB admin database and assign the
required roles to the user:
- For the MongoDB database version 2.4, run the following command:
db.addUser({ user:
username
, pwd:password
, roles: [ 'clusterAdmin', 'readAnyDatabase', 'dbAdminAnyDatabase' ] }) - For the MongoDB database version 2.6, run the following command:
db.createUser({user:
username
, pwd:password
, roles: [ 'clusterAdmin', 'readAnyDatabase', 'dbAdminAnyDatabase' ] }) - For the MongoDB database version 3.x and 4.x, run the following
command:
db.createUser({user:
username
, pwd:password
, roles: [ 'clusterMonitor', 'readAnyDatabase', 'dbAdminAnyDatabase' ] })
- For the MongoDB database version 2.4, run the following command:
- Run the following command to verify that the user is added to the admin
database:
db.auth(
username
,password
)Return code
1
indicates that the user is added, whereas the return code0
indicates that the user addition failed.
- Run the following command to connect to the MongoDB database:
Roles | MongoDB database version | Attribute groups |
---|---|---|
dbAdminAnyDatabase | 2.x, 3.x, 4.x | Response Times |
readAnyDatabase | 2.x, 3.x, 4.x |
|
clusterAdmin | 2.x, 3.x, 4.x |
|
clusterMonitor | 2.x, 3.x, 4.x |
|
- For remote monitoring of the MongoDB server, see the two prerequisites
- Since MongoDB agent requires mongo shell to collect information remotely from the MongoDB server, the system on whichMongoDB agent is installed and configured must have an instance of MongoDB server. The mongo shell of the MongoDB server on the agent machine is used to connect to the remote MongoDB server for monitoring.
- In /etc/hosts file of the system that hosts the agent, there is an entry of the remote machine.
About this task
instance_name:host_name:pc
,
where pc is the two character product code of your agent. The managed system name
can contain up to 32 characters. The instance name can contain up to 28 characters, excluding the
length of your host name. For example, if you specify Mongo2
as your instance name,
your managed system name is Mongo2:hostname:KJ
.The product version and the agent version often differ. The directions here are for the most current release of this agent. For information about how to check the version of an agent in your environment, see Using agent commands. For detailed information about the agent version list and what's new for each version, see the Change history.
- For the agent to successfully collect data, start the agent with the super (root) user, or use the same user ID to start the agent and the mongod process.
- In an environment where MongoDB runs as a cluster, ensure that you install the agent on the same system where the router process is running. Configure the agent on the same system with the IP address and port number of that system and the setup TYPE as 1.
- In an environment where MongoDB runs as a cluster in authentication mode, ensure that you add the same user ID with the required rights on all the shards in the cluster.
You can configure the agent by using the default settings, by editing the silent response file, or by responding to prompts.