MMS is a cloud-based or on-premises service that enables you to monitor your MongoDB cluster. The on-premise version is available with the Enterprise subscription only. It gives you one central place that lets the administrators monitor the health of the server instances and the boxes on which the instances are running. In this recipe, we will see what the software requirements are and how to set up MMS for Mongo.
We will be starting a single instance of mongod
, which we will be using for the purpose of monitoring. Refer to the Single node installation of MongoDB recipe in Chapter 1, Installing and Starting the MongoDB Server, to start a MongoDB instance and connect to it from a Mongo shell. The monitoring agent, used to send the statistics of the Mongo instance to the monitoring service, uses Python and PyMongo. Refer to the Installing PyMongo recipe in Chapter 3, Programming Language Drivers, to know more about how to install Python and PyMongo, the Python client of MongoDB.
monitoring-agent.config
file, which will be present in the configuration folder selected while installing the agent.mmsApiKey
key in the file and set its value to the API key that was noted down earlier in step 3.services.msc
on MS Windows, which can be done by typing services.msc
in the Run dialog (Windows + R). The service will be named MMS Monitoring Agent. On the web page, click on the Verify Agent button. If all goes well, the started agent will be verified and the success message will be shown.We have successfully set up MMS and added one host to it, which would be monitored.
In this recipe, we have set up the MMS agent and monitoring for a standalone MongoDB instance. The installation and setup process is pretty simple. We also added a standalone instance and all was ok.
Suppose we have a replica set up and running (refer to the Starting multiple instances as part of a replica set recipe in Chapter 1, Installing and Starting the MongoDB Server, for more details on how to start a replica set), and the three members are listening to ports 27000
, 27001
, and 27002
, respectively. Refer to step 7 in the How to do it… section, where we set up one standalone host. If we select Replica Set in the dropdown for Host Type, and for the internal hostname we give a valid hostname of any member of the replica set (in my case, Amol-PC
and port 27001
were given, which is a secondary instance), all other instances will automatically be discovered and they will be visible under the hosts, as shown in the following screenshot:
We didn't see what is to be done when security is enabled on the cluster, which is pretty common in production environments. If authentication is enabled, we need proper credentials for the MMS agent to gather the statistics. The DB username and password that we give while adding a new host (step 7 of the How to do it… section) should have a minimum of clusterAdmin
and readAnyDatabase
roles.
What we saw in this recipe was setting up an MMS agent and creating an account from the MMS console. However, we can add groups and users for the MMS console as administrators, granting various users privileges for performing various operations on different groups. In the next recipe, we will throw some light on user and group management in the MMS console.