Step-by-Step Guide to Monitoring MongoDB with Zabbix Agent 2
This tutorial explains how to use Zabbix Agent 2 to monitor MongoDB databases and clusters, covering the required read‑only user setup, relevant Zabbix templates, key metrics such as jumbo chunks, connection pool stats, server status, collection and replSet information, and practical configuration examples.
What to Monitor?
Zabbix provides templates for both MongoDB clusters and individual nodes, collecting metrics like node and cluster status, storage information, connection pool stats, jumbo chunk counts, collection usage, operation logs, and replSet status.
Getting Jumbo Chunks Count
Jumbo chunks occur when a chunk exceeds the default size and cannot be split, leading to load imbalance. The following command retrieves the count:
<code>use config
db.chunks.find({"jumbo":true})</code>Getting connPool.stats Information
Use this command to obtain connection pool statistics:
<code>db.runCommand({"connPoolStats" : 1})</code>Getting MongoDB Server Status
Retrieve server status with:
<code>db.runCommand({serverStatus:1,recordStats:0})</code>Getting Collection Information
Automatic discovery returns each collection’s stats; you can exclude specific collections with macros. Example command:
<code>db.runCommand({collStats : "collections_name"})</code>Getting replSet Status
Collect replSet status (requires replSet configuration):
<code>db.adminCommand({replSetGetStatus:1})</code>Getting Database Information
Retrieve each database’s storage stats:
<code>db.runCommand({dbStats:1})</code>Polling Oplog for replSet Information
The oplog in the local database stores replSet data. Use the following command to get its status, size, and time range:
<code>db.getReplicationInfo()</code>How to Set Up Monitoring?
First, create a read‑only user in MongoDB with appropriate roles:
<code>use admin
db.auth("admin", "[email protected]")
db.createUser({
"user": "zabbix",
"pwd": "zabbix123",
"roles": [
{ role: "readAnyDatabase", db: "admin" },
{ role: "clusterMonitor", db: "admin" }
]
})</code>Instead of embedding connection details in the URL, define named sessions for each instance, which simplifies monitoring multiple servers:
<code>Plugins.Mongo.Sessions.Mongo1.Uri=tcp://127.0.0.1:27017
Plugins.Mongo.Sessions.Mongo1.User=<UsernameForMongo1>
Plugins.Mongo.Sessions.Mongo1.Password=<PasswordForMongo1>
Plugins.Mongo.Sessions.Mongo2.Uri=tcp://127.0.0.1:27018
Plugins.Mongo.Sessions.Mongo2.User=<UsernameForMongo2>
Plugins.Mongo.Sessions.Mongo2.Password=<PasswordForMongo2></code>After defining sessions, use the session name in item keys:
<code>mongodb.ping[Mongo1]
mongodb.ping[Mongo2]</code>Finally, refer to the official Zabbix MongoDB integration documentation for macro definitions, discovery rules, and trigger configurations:
https://www.zabbix.com/integrations/mongodb
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.