Overview
MongoDB Enterprise can provide database metrics via SNMP, in
support of centralized data collection and aggregation. This procedure
explains the setup and configuration of a mongod instance
as an SNMP subagent, as well as initializing and testing of SNMP
support with MongoDB Enterprise.
Tip
Troubleshoot SNMP and Monitor MongoDB Windows with SNMP for complete instructions on using MongoDB with SNMP on Windows systems.
Considerations
Configuration Files
MongoDB Enterprise includes the following SNMP configuration files:
MONGOD-MIB.txt:The management information base (MIB) file that defines MongoDB's SNMP output. On Ubuntu and Debian platforms, this file is shipped compressed as
MONGOD-MIB.txt.gzand must be decompressed withgunzip.mongod.conf.subagent:The configuration file to run
mongodas the SNMP subagent. This file sets SNMP run-time configuration options, including theagentXSocketto connect to the SNMP master.mongod.conf.master:The configuration file to run
mongodas the SNMP master. This file sets SNMP run-time configuration options, including theagentaddressto run on.
The MongoDB SNMP configuration files are provided with your MongoDB Enterprise installation, as follows:
If you installed MongoDB Enterprise via a package manager, these files are installed to the following directory as part of the package installation process:
PlatformPathRHEL / CentOS
/usr/share/doc/mongodb-enterprise-server-4.4.29Ubuntu / Debian
/usr/share/doc/mongodb-enterprise-serverSUSE
/usr/share/doc/packages/mongodb-enterprise-serverIf you installed MongoDB Enterprise from a
.tgztarball, these files were included in the tarball.
Procedure
Copy configuration files.
Copy the MongoDB SNMP configuration files from their installation location to their target directories, according to your platform:
Navigate to the location where the SNMP files were installed. For example, if you installed the latest version of MongoDB via the
yumpackage manager:cd /usr/share/doc/mongodb-enterprise-server-4.4.29 Copy the two MongoDB SNMP files to their target directories:
sudo cp MONGOD-MIB.txt /usr/share/snmp/mibs/ sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
Navigate to the location where the SNMP files were installed. For example, if you installed MongoDB via the
aptpackage manager:cd /usr/share/doc/mongodb-enterprise-server Copy the
MONGOD-MIB.txt.gzfile to its target directory, and unzip it:sudo cp MONGOD-MIB.txt.gz /usr/share/snmp/mibs/ sudo gunzip /usr/share/snmp/mibs/MONGOD-MIB.txt.gz Copy the
mongod.conf.subagentfile to its target directory:sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
Navigate to the location where the SNMP files were installed. For example, if you installed the latest version of MongoDB via the
zypperpackage manager:cd /usr/share/doc/packages/mongodb-enterprise-server Copy the two MongoDB SNMP files to their target directories:
sudo cp MONGOD-MIB.txt /usr/share/snmp/mibs/ sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
Configure SNMP.
Edit the /etc/snmp/snmpd.conf file, and add the following:
# sec.name source community com2sec local localhost mongodb # group.name sec.model sec.name group MyRWGroup any local # incl/excl subtree mask view all included .1 80 # context sec.model sec.level prefix read write notif access MyRWGroup "" any noauth 0 all all all master agentx AgentXSocket /tmp/agentx/master AgentXPerms 0777 0777 mongod mongod
Install
snmpdif it is not already installed:sudo apt-get install snmpd Edit the
/etc/snmp/snmpd.conffile, and add the following:# sec.name source community com2sec local localhost mongodb # group.name sec.model sec.name group MyRWGroup any local # incl/excl subtree mask view all included .1 80 # context sec.model sec.level prefix read write notif access MyRWGroup "" any noauth 0 all all all AgentXSocket /tmp/agentx/master AgentXPerms 0777 0777 mongodb mongodb
Edit the /etc/snmp/snmpd.conf file, and add the following:
# sec.name source community com2sec local localhost mongodb # group.name sec.model sec.name group MyRWGroup any local # incl/excl subtree mask view all included .1 80 # context sec.model sec.level prefix read write notif access MyRWGroup "" any noauth 0 all all all master agentx AgentXSocket /tmp/agentx/master AgentXPerms 0777 0777 mongod mongod
This configuration defines a UNIX domain socket for communication
between the master (snmpd) and sub-agent (MongoDB), and
defines basic SNMP permissions for access to the relevant MongoDB
SNMP fields.
Note
To bind your master to a non-localhost IP address, add that IP
address to the agentaddress field in the
/etc/snmp/snmpd.conf file, and update the appropriate network
security ACLs to permit a valid address range. An address range of
10.0.0.0/8 with a security name of "mynetwork" has been provided in
the mongod.conf.master configuration file as an example.
The above configuration is given as an example only; you may wish to customize permissions based on your site security requirements. While MongoDB support can provide guidance on configuring MongoDB for SNMP, configuring SNMP on operating systems is out of scope.
Start MongoDB.
Start mongod with the
snmp-subagent to send data to the
SNMP master.
mongod --snmp-subagent
Confirm SNMP data retrieval.
Verify that MongoDB is accessible for SNMP queries with the
snmpwalk testing command.
Install
snmpwalkon your system:sudo yum install net-snmp-utils Run
snmpwalkwith the following parameters to verify the ability to collect data frommongod:snmpwalk -m /usr/share/snmp/mibs/MONGOD-MIB.txt -v 2c -c mongodb 127.0.0.1:161 1.3.6.1.4.1.34601
DEBIAN ONLY: If necessary, add the
non-freerepository to your/etc/apt/sources.listfile to access thesnmp-mibs-downloaderpackage. For example, on Debian 9 "Stretch", the primary repo entries might look like this:deb http://deb.debian.org/debian stretch main non-free deb-src http://deb.debian.org/debian stretch main non-free DEBIAN / UBUNTU: Install the
snmp-mibs-downloaderpackage to supply necessary MIB files, then restart thesnmpdservice to reload the new MIB files:sudo apt-get update sudo apt-get -y install snmp-mibs-downloader sudo service snmpd restart DEBIAN / UBUNTU: Run
snmpwalkwith the following parameters to verify the ability to collect data frommongod:snmpwalk -m /usr/share/snmp/mibs/MONGOD-MIB.txt -v 2c -c mongodb 127.0.0.1:161 1.3.6.1.4.1.34601
snmpwalk -m /usr/share/snmp/mibs/MONGOD-MIB.txt -v 2c -c mongodb 127.0.0.1:161 1.3.6.1.4.1.34601
The snmpwalk command should display current values for SNMP fields
such as sysUpTime, and memoryResident, among others.
Optional: Run MongoDB as SNMP Master
You can run mongod with the
snmp-master option for testing
purposes. To do this, use the SNMP master configuration file instead of
the subagent configuration file. From the directory containing the
unpacked MongoDB installation files:
cp mongod.conf.master /etc/snmp/mongod.conf
Note
To bind your master to a non-localhost IP address, add that IP
address to the agentaddress field in the
/etc/snmp/mongod.conf file, and update the appropriate network
security ACLs to permit a valid address range. An address
range of 10.0.0.0/8 with a security name of "mynetwork" has been
provided in the master configuration file as an example.
Then, start mongod with the
snmp-master option:
mongod --snmp-master