Bobcares

wesupport

CLIENT AREACall Us 1-800-383-5193
Bobcares

wesupport

Call Us 1-800-383-5193
Bobcares

wesupport

Call Us 1-800-383-5193

Need help?

Our experts have had an average response time of 13.52 minutes in October 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to monitor MongoDB with Nagios XI

by | May 19, 2021

We can monitor a MongoDB server with Nagios using the MongoDB Server Configuration Wizard.

The information we collect by monitoring MongoDB database will help us to determine when documents are written into the database or if the size of the database is getting too large.

As a part of our Server Management Services, we help our customers with requests related to Nagios regularly.

Today, let us discuss the possible steps involved in the setup.


 

Enable Authentication

The first step is to enable authentication in MongoDB Server. To enable authentication, follow the steps given below:

Initially, start MongoDB without access control.

mongod --port 27017 --dbpath /var/lib/mongodb

Then, connect to the instance.

mongo --port 27017 --host xxx.xxx.xxx.xxx

Once done, create the user administrator.

From the mongo shell, add a user with the userAdminAnyDatabase role in the admin database. Include additional roles as needed for this user. For example, the following creates the user myUserAdmin in the admin database with the userAdminAnyDatabase role and the readWriteAnyDatabase role.

use admin
db.createUser(
{
user: "myUserAdmin",
pwd: passwordPrompt(), // or cleartext password
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)

Now, Re-start the MongoDB instance with access control using the steps below:

  • Shut down the mongod instance. For example, from the mongo shell, issue the following command: db.adminCommand( { shutdown: 1 } )
  • Exit the mongo shell.
  • Start the mongod with access control enabled.
  • If we start the mongod from the command line, add the –auth command line option:
    mongod --auth --port 27017 --dbpath /var/lib/mongodb

     

  • If we start the mongod using a configuration file, add the security.authorization configuration file setting:
    security:
    authorization: enabled

Clients that connect to this instance must now authenticate themselves as a MongoDB user. Clients can only perform actions as determined by their assigned roles.
 

Allow remote connections to MongoDB server:

We should have a user in the admin database that has the role of clusterAdmin. This role is required by MongoDB to access statistics on the MongoDB server.

We will also be required to allow remote connections to MongoDB server.

bindIp

To bind to all IPv4 addresses, we can specify the bind IP address of 0.0.0.0. Alternatively, to bind to all IPv4 and IPv6 addresses, we can specify the bind ip address of ::,0.0.0.0 or alternatively, use the new net.bindIpAll setting or the new command-line option –bind_ip_all.

To override and bind to other ip addresses, we can use the net.bindIp configuration file setting or the –bind_ip command-line option to specify a list of hostnames or ip addresses.

For example, the following mongod instance binds to both the localhost and the hostname My-Example-Hostname, which is associated with the IP address 198.51.100.1:

mongod --bind_ip localhost,My-Example-Hostname

In order to connect to this instance, remote clients must specify the hostname or its associated ip address 198.51.100.1:

mongo --host My-Example-Hostname
mongo --host 198.51.100.1

 

Firewall Rules:

To explicitly allow traffic to the mongod instance from the application server, run the commands given below:

iptables -A INPUT -s -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

Replace with the IP address of the application server.

The first rule allows all incoming traffic from on port 27017, which allows the application server to connect to the mongod instance. The second rule, allows outgoing traffic from the mongod to reach the application server.
 

Monitor a MongoDB Database with Nagios XI

The MongoDB Database configuration wizard will be used to set up the service checks for our MongoDB database. In the Nagios XI menu, navigate to Configure > Configuration Wizards and click the MongoDB Database wizard.

Monitor MongoDB with Nagios XI

Step 1: Provide the address of MongoDB server in the Address field. Change the default port if required. Enter the Username and Password of the account that has clusterAdmin access. We need to enter the database we would like to monitor in the Database field. Click the Next button.

Step 2: Here we can define the monitoring options.

In the first section, make sure the Host Name field is correct, this is the name the host will be given in Nagios XI. The MongoDB Database Metrics section allows us to select which metrics to monitor on our MongoDB Database. Select the checks we wish to perform and what the warning and critical values will be for each one. Once we have selected the checks we want to monitor, click Next to continue.

Step 3: Complete the wizard by choosing the required options and then click on Finish in the final step of the wizard.

Once the wizard applies the configuration, click the View status details for our MongoDB server link to see the new host and services that were created.
 

Monitoring a MongoDB Server

We can use the MongoDB Server configuration wizard to set up the service checks for our MongoDB server. In the Nagios XI menu, navigate to Configure > Configuration Wizards and click the MongoDB Server wizard.

Step 1: Provide the address of MongoDB server in the Address field. Change the default port if required. Enter the Username and Password of the account that has clusterAdmin access. Click Next to proceed.

Step 2: Here we can define the monitoring options.

In the first section, make sure the Host Name field is correct, this is the name the host will be given in Nagios XI. The MongoDB Server Metrics section allows us to select which metrics to monitor on our MongoDB Server. Select the checks we wish to perform on the server and set warning and critical values for our alert thresholds.

If we use replication, there are some checks we can perform on our replication set such as: status, lag and lag percentage. By default, these are off because not all MongoDB servers are set up with replication. Once we have selected the checks we want to monitor, click Next to continue.

Step 3: Complete the wizard by choosing the required options and then click on Finish in the final step of the wizard.

Once the wizard applies the configuration, click the View status details for our MongoDB server link to see the new host and services that were created.

[Need any further assistance with Nagios errors? – We’re available 24*7]
 

Conclusion

In short, we can monitor a MongoDB server with Nagios using the MongoDB Server Configuration Wizard. Today, we saw how our Support Engineers perform this.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags