Databases 9 min read

Deploy and Use the Open‑Source MongoDB Visual Monitoring Tool (mongo_monitor)

This guide explains how to set up the mongo_monitor tool—a PHP‑based graphical monitor for MongoDB—by installing required PHP extensions, configuring a MySQL schema, adding MongoDB credentials, customizing email and WeChat alerts, scheduling data collection via cron, and accessing the web dashboard.

dbaplus Community
dbaplus Community
dbaplus Community
Deploy and Use the Open‑Source MongoDB Visual Monitoring Tool (mongo_monitor)

Tool Overview

The mongo_monitor project provides a web‑based graphical dashboard for monitoring MongoDB clusters (MongoDB 3.2+). It displays connection count, QPS/TPS, memory usage, replica‑set status and replication lag, and can send alerts via WeChat or email. No agent is required on the MongoDB servers.

Prerequisites

PHP 5.4+ with the following extensions: php‑pear, php‑devel, php, gcc, openssl, openssl‑devel, cyrus‑sasl, cyrus‑sasl‑devel, httpd, mysql, php‑mysql.

MySQL server for storing monitoring data.

Apache (httpd) to serve the PHP application.

Install the packages on a CentOS/RHEL host:

yum install -y php-pear php-devel php gcc openssl openssl-devel cyrus-sasl cyrus-sasl-devel httpd mysql php-mysql

MongoDB PHP Driver Installation

Install the legacy mongo driver via PECL: pecl install mongo Append the driver to the PHP configuration and restart Apache:

echo "extension=mongo.so" >> /etc/php.ini
service httpd restart

If PECL fails, download the source tarball (e.g., mongodb-1.3.4.tgz for PHP 5.4) and compile manually.

MySQL Schema Setup

Create the mongo_monitor database and import the schema:

mysql -uroot -pYOUR_PASSWORD < mongo_monitor_schema.sql

Insert Monitoring Targets

Populate mongo_status_info with one row per MongoDB instance. Example:

INSERT INTO mongo_status_info (ip, tag, USER, pwd, PORT, authdb, send_mail_to_list, send_weixin_to_list, threshold_alarm_connection, threshold_alarm_repl)
VALUES ('10.10.159.31', 'MongoDB_Test_1', 'admin', 'hechunyang', '27017', 'admin', '[email protected]', 'hechunyang', 1000, 60);

Key column meanings: ip: MongoDB host address. tag: Friendly name for the instance. USER / pwd: Root credentials (required for db.runCommand({serverStatus:1,repl:1}) and db.adminCommand({replSetGetStatus:1})). PORT: MongoDB port. authdb: Authentication database (usually admin). send_mail_to_list, send_weixin_to_list: Recipient lists for alerts. threshold_alarm_connection: Connection‑count alarm threshold. threshold_alarm_repl: Replication‑lag alarm threshold (seconds).

Configuration Files

Database connection (conn.php)

$con = mysqli_connect("127.0.0.1", "admin", "YOUR_PASSWORD", "mongo_monitor", "3306")
    or die("Database connection error" . mysqli_error());

Replace the credentials with those of your MySQL instance.

Email alert (mail/mail.php)

system("./mail/sendEmail -f [email protected] -t '{$this->send_mail_to_list}' -s smtp.domain.com:25 -u '{$this->alarm_subject}' -o message-charset=utf8 -o message-content-type=html -m 'Alert: {$this->alarm_info}' -xu [email protected] -xp 'YOUR_PASSWORD' -o tls=no");

Adjust the sender address, SMTP server, and authentication details.

WeChat alert

Configure the WeChat enterprise account according to the instructions in the GitHub repository

https://github.com/X-Mars/Zabbix-Alert-WeChat/blob/master/README.md

. The script weixin/wechat.py must be executable ( chmod 755 wechat.py).

Cron Jobs for Data Collection

Schedule the two PHP collectors to run every minute:

*/1 * * * * cd /var/www/html/mongo_monitor; /usr/bin/php check_mongo_status.php > /dev/null 2>&1
*/1 * * * * cd /var/www/html/mongo_monitor; /usr/bin/php check_mongo_repl.php > /dev/null 2>&1

Web Interface Adjustments

Change the auto‑refresh interval (default 600 seconds) by editing mongo_replset_monitor.php and modifying the meta tag: <meta http-equiv="refresh" content="600"> Set content to the desired number of seconds.

Accessing the Dashboard

After deployment, open the following URL in a browser (replace yourIP with the server address):

http://yourIP/mongo_monitor/mongo_replset_monitor.php

The page can be embedded in automation platforms for quick access.

Source Repository

The complete source code and release archive are hosted at:

https://github.com/hcymysql/mongo_monitor
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DeploymentAlertingopen sourcePHPMongoDBDatabase Tools
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.