MMS is a cloud-based or on-premise service that enables you to monitor your MongoDB cluster. The on-premise version is available with an 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 use for monitoring purposes. Refer to the recipe Installing single node MongoDB from Chapter 1, Installing and Starting the Server to start a MongoDB instance and connect to it from a Mongo shell. The monitoring agent used for sending the statistics of the mongo instance to the monitoring service uses Python and pymongo. Refer to the recipe Connecting to a single node using a Python client in Chapter 1, Installing and Starting the Server to learn more about how to install Python and pymongo, the Python client of MongoDB.
If you don't already have a MMS account, then log in to https://mms.mongodb.com/ and sign up for an account. On signing up and logging in, you should see the following page:
Click on the Get Started button under Monitoring.
monitoring-agent.config
. It will be present in the configuration folder selected while installing the agent.mmsApiKey
in the file and set its value to the API key that was noted down in step 1.services.msc
on Windows, which can be done by typing services.msc
in the run dialog (Windows + R) and start the service manually). The service would 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 a success message will be shown.Once the host's details are added, click on the Verify Host button. Once verification is done, click the Start Monitoring button.
We have successfully set up MMS and added one host to it that will be monitored.
In this recipe, we set up an 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 okay.
Suppose we have a replica set up and running (refer to the recipe Starting multiple instances as part of a replica set in Chapter 1, Installing and Starting the Server, for more details on how to start a replica set) and the three members are listening to ports 27000
, 27001
, and 27002
. Refer to point number 6 in the How to do it… section where we set up one standalone host. In the drop-down menu for Host Type select Replica Set and in the Internal hostname, 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 be automatically discovered and will be visible under the hosts, as shown here:
We didn't see what is to be done when security is enabled on the cluster, which is pretty common in production environments and we have replica sets or shard setup. If authentication is enabled, we need proper credentials for the MMS agent to gather the statistics. The DB Username and DB Password that we give while adding a new host (point number 6 in the How to do it… section) should have a minimum of clusterAdmin
and readAnyDatabase
role.
What we saw in this recipe was how to set up MMS agent and create an account from the MMS console. However, we can add groups and users for the MMS console as an administrator 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.