Monitor MongoDB With SNMP on Linux在Linux上使用SNMP监控MongoDB

On this page本页内容

Note注意
Enterprise Feature企业特色

SNMP is only available in MongoDB Enterprise.SNMP仅在MongoDB Enterprise中可用。

Overview概述

MongoDB Enterprise can provide database metrics via SNMP, in support of centralized data collection and aggregation. MongoDB Enterprise可以通过SNMP提供数据库指标,以支持集中的数据集合和聚合。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.本过程解释了作为SNMP子代理的mongod实例的设置和配置,以及使用MongoDB Enterprise初始化和测试SNMP支持。

Tip提示
See also: 参阅:

Troubleshoot SNMP and Monitor MongoDB Windows with SNMP for complete instructions on using MongoDB with SNMP on Windows systems.对SNMP进行故障排除使用SNMP监控MongoDB Windows,以获取有关在Windows系统上使用MongoDB with SNMP的完整说明。

Considerations考虑因素

  • SNMP support is only available in mongod. SNMP支持仅在mongod中可用。Other MongoDB tools such as mongos do not support SNMP.其他MongoDB工具(如mongos)不支持SNMP。
  • mongod does not support the use of SNMP traps.

Configuration Files配置文件

MongoDB Enterprise includes the following SNMP configuration files:MongoDB Enterprise包括以下SNMP配置文件:

  • MONGOD-MIB.txt:

    The management information base (MIB) file that defines MongoDB's SNMP output. 定义MongoDB的SNMP输出的管理信息库(MIB)文件。On Ubuntu and Debian platforms, this file is shipped compressed as MONGOD-MIB.txt.gz and must be decompressed with gunzip.在Ubuntu和Debian平台上,该文件以MONGOD-MIB.txt.gz的形式压缩,必须使用gunzip解压。

  • mongod.conf.subagent:

    The configuration file to run mongod as the SNMP subagent. 要作为SNMP子代理运行mongod的配置文件。This file sets SNMP run-time configuration options, including the agentXSocket to connect to the SNMP master.此文件设置SNMP运行时配置选项,包括用于连接到SNMP主机的agentXSocket

  • mongod.conf.master:

    The configuration file to run mongod as the SNMP master. mongod作为SNMP主机运行的配置文件。This file sets SNMP run-time configuration options, including the agentaddress to run on.此文件设置SNMP运行时配置选项,包括要运行的agentaddress

The MongoDB SNMP configuration files are provided with your MongoDB Enterprise installation, as follows:MongoDB SNMP配置文件随MongoDB Enterprise安装一起提供,如下所示:

  • If you installed MongoDB Enterprise via a package manager, these files are installed to the following directory as part of the package installation process:如果您通过软件包管理器安装了MongoDB Enterprise,这些文件将作为软件包安装过程的一部分安装到以下目录:

    PlatformPath
    RHEL / CentOS/usr/share/doc/mongodb-enterprise-server-5.0.6
    Ubuntu / Debian/usr/share/doc/mongodb-enterprise-server
    SUSE/usr/share/doc/packages/mongodb-enterprise-server
  • If you installed MongoDB Enterprise from a .tgz tarball, these files were included in the tarball.如果您是从.tgz tarball安装MongoDB Enterprise,这些文件都包含在tarball中。

Procedure过程

1

Copy configuration files.复制配置文件。

Copy the MongoDB SNMP configuration files from their installation location to their target directories, according to your platform:根据您的平台,将MongoDB SNMP配置文件从安装位置复制到目标目录:

  1. Navigate to the location where the SNMP files were installed. For example, if you installed the latest version of MongoDB via the yum package manager:

    cd /usr/share/doc/mongodb-enterprise-server-5.0.6
  2. 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
  1. Navigate to the location where the SNMP files were installed. For example, if you installed MongoDB via the apt package manager:

    cd /usr/share/doc/mongodb-enterprise-server
  2. Copy the MONGOD-MIB.txt.gz file 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
  3. Copy the mongod.conf.subagent file to its target directory:

    sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
  1. Navigate to the location where the SNMP files were installed. For example, if you installed the latest version of MongoDB via the zypper package manager:

    cd /usr/share/doc/packages/mongodb-enterprise-server
  2. 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
2

Configure SNMP.配置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
  1. Install snmpd if it is not already installed:

    sudo apt-get install snmpd
  2. 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
    
    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.此配置定义了用于主代理snmpd)和子代理(MongoDB)之间通信的UNIX域套接字,并定义了访问相关MongoDB SNMP字段的基本SNMP权限。

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. 要将主机绑定到非本地主机IP地址,请将该IP地址添加到/etc/snmp/snmpd.conf文件中的agentaddress字段,并更新相应的网络安全ACL以允许有效的地址范围。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.例如,mongod.conf.master配置文件中提供了10.0.0.0/8的地址范围,安全名称为“mynetwork”。

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.虽然MongoDB支持可以为配置MongoDB for SNMP提供指导,但在操作系统上配置SNMP超出了范围。

3

Start SNMP.

Start SNMP on your system using the initialization system appropriate for your version of Linux:使用适合您的Linux版本的初始化系统在系统上启动SNMP:

  • For Linux systems using systemd (systemctl command):对于使用systemdsystemctl命令)的Linux系统:

    sudo systemctl start snmpd
  • For Linux systems using System V init (service command):对于使用System V initservice命令)的Linux系统:

    sudo service snmpd start
4

Start MongoDB.启动MongoDB。

Start mongod with the snmp-subagent to send data to the SNMP master.使用snmp-subagent启动mongod,将数据发送到snmp主机。

mongod --snmp-subagent
5

Confirm SNMP data retrieval.确认SNMP数据检索。

Verify that MongoDB is accessible for SNMP queries with the snmpwalk testing command.使用snmpwalk测试命令验证MongoDB是否可用于SNMP查询。

  1. Install snmpwalk on your system:

    sudo yum install net-snmp-utils
  2. Run snmpwalk with the following parameters to verify the ability to collect data from mongod:

    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
  1. DEBIAN ONLY: If necessary, add the non-free repository to your /etc/apt/sources.list file to access the snmp-mibs-downloader package. 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
  2. DEBIAN / UBUNTU: Install the snmp-mibs-downloader package to supply necessary MIB files, then restart the snmpd service to reload the new MIB files:

    sudo apt-get update
    sudo apt-get -y install snmp-mibs-downloader
    sudo service snmpd restart
  3. DEBIAN / UBUNTU: Run snmpwalk with the following parameters to verify the ability to collect data from mongod:

    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.snmpwalk命令应该显示SNMP字段的当前值,例如sysUpTimememoryResident等。

Note注意

The port used in the above snmpwalk testing command, port 161, is the default port for the snmpd service, not the primary port for the mongod. 上述snmpwalk测试命令中使用的端口端口161是snmpd服务的默认端口,而不是mongod的主端口If you have configured a different port for your snmpd service, supply that here instead.如果您为snmpd服务配置了不同的端口,请在此处提供。

Optional: Run MongoDB as SNMP Master可选:将MongoDB作为SNMP主机运行

You can run mongod with the snmp-master option for testing purposes. 出于测试目的,可以使用snmp-master选项运行mongodTo do this, use the SNMP master configuration file instead of the subagent configuration file. 为此,请使用SNMP主配置文件而不是子代理配置文件。From the directory containing the unpacked MongoDB installation files:从包含未打包MongoDB安装文件的目录:

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. 要将主机绑定到非本地主机IP地址,请将该IP地址添加到/etc/snmp/mongod.conf文件中的agentaddress字段,并更新相应的网络安全ACL以允许有效的地址范围。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.主配置文件中提供了一个地址范围为10.0.0.0/8、安全名称为“mynetwork”的示例。

Then, start mongod with the snmp-master option:然后,使用snmp-master选项启动mongod

mongod --snmp-master
←  Free MonitoringMonitor MongoDB Windows with SNMP →