I&B Monitoring Platform documentation

MongoDB exporter

Installation of Prometheus MongoDB exporter in production environment consists from following high level steps:

  1. Install exporter;

  2. Configure authentication;

  3. Configure firewall;

  4. Configure service for autostart and restart;

  5. Check access to exporter from I&B monitoring platform.

1. Install Prometheus MongoDB exporter.

  1. Check latest version, available platforms on MongoDB exporter GitHub page and make necessary changes in variables on next step.

  2. Prepare environment variables to simplify installation and configuration process.

export EXPORTER_VERSION=0.47.1
export EXPORTER_PLATFORM=linux-amd64
  1. Download exporter

wget https://github.com/percona/mongodb_exporter/releases/download/v$EXPORTER_VERSION/mongodb_exporter-$EXPORTER_VERSION.$EXPORTER_PLATFORM.tar.gz
  1. Create directory /usr/local/bin/mongodb_exporter and untar exporter into it.

sudo mkdir -p /usr/local/bin/mongodb_exporter
sudo tar xvfz mongodb_exporter-$EXPORTER_VERSION.$EXPORTER_PLATFORM.tar.gz -C /usr/local/bin/mongodb_exporter --strip-components=1
  1. Create prometheus user. If it already exist - go to step 6.

Fedora (RHEL, CentOS)

sudo useradd -M -s /sbin/nologin prometheus
  • -M (or --no-create-home): This option prevents the creation of a home directory for the new user;

  • -s /sbin/nologin: This option sets the user's login shell to /sbin/nologin. This effectively prevents the user from interactively logging into the system. While the user won't have a password set, this further ensures they cannot log in.

Debian (Ubuntu)

sudo useradd -s /sbin/nologin prometheus --no-create-home
  1. Make prometheus user owner of mongodb_exporter directory

sudo chown -hR prometheus:prometheus /usr/local/bin/mongodb_exporter

2. Configure firewall

Configure firewall on resource

  1. MongoDB exporter uses default port 9216, so allow it in firewall on resource.

Fedora (RHEL, CentOS)

sudo firewall-cmd --zone=public --add-port=9216/tcp --permanent
sudo systemctl reload firewalld

Check firewall configuration

sudo firewall-cmd --list-all

You should see in output:

ports: 9216/tcp

Debian (Ubuntu)

sudo ufw allow 9216

You should see in output:

Rules updated
Rules updated (v6)

Check firewall configuration

sudo ufw status

You should see in output:

To                             Action          From
--                             ------          ----
9216                           ALLOW           Anywhere

3. Configure authentication for exporter

Do the steps described in Exporters configuration → Authentication section.

4. Check configuration

  1. Run mongodb_exporter. To do this, you need to specify the connection string to the database, which contains an username, password, mongodb hostname or address and port for connecting to a database. The string looks like this: --mongodb.uri=mongodb://user:password@127.0.0.1:17001

/usr/local/bin/mongodb_exporter/mongodb_exporter \
    --web.config=/usr/local/bin/mongodb_exporter/web-config.yml \
    --mongodb.uri=mongodb://user:password@mongodb-hostbane-or-ip:port

Check with browser if it is accessible at:

https://resource-hostname-or-ip:9216/metrics

After entering exporter’s user name and password you should see page like this:

# HELP mongodb_ss_wt_log_log_bytes_written serverStatus.wiredTiger.log.
# TYPE mongodb_ss_wt_log_log_bytes_written untyped
mongodb_ss_wt_log_log_bytes_written 2.6208e+06
...

Stop mongodb exporter with Ctrl-c in terminal where you run it.

Make mongodb_exporter service for autostart and restart.

Create file with your preferred text editor, for example nano …

sudo nano /etc/systemd/system/mongodb_exporter.service

… and paste following text into it.

In string --mongodb.uri=mongodb://user:password@127.0.0.1:17001 you need to replace user with your database user, pass with that user's password, 127.0.0.1 with the IP address or network name of the database server, 17001 with the port number on which this server accepts connections.

[Unit]
Description=mongodb exporter

[Service]
User=prometheus
ExecStart=/usr/local/bin/mongodb_exporter/mongodb_exporter \
          --web.config=/usr/local/bin/mongodb_exporter/web-config.yml \
          --mongodb.uri=mongodb://user:password@mongodb-hostbane-or-ip:port

[Install]
WantedBy=multi-user.target

Save file and exit editor.

Start service …

sudo systemctl daemon-reload
sudo systemctl start mongodb_exporter
sudo systemctl enable mongodb_exporter

… and check

sudo systemctl status mongodb_exporter

You should see following output similar to:

Снимок экрана 2025-09-22 100122.png

In case of any problem, you should view log entries for service:

journalctl -u mongodb_exporter.service -e

Now mongodb exporter is ready to accept data and then expose it to Prometheus.