§2024-05-22
-
After I setup zabbix server, how to moitor mongodb replicationSet?
-
ChatGPT
¶To monitor a MongoDB replica set with Zabbix, you'll need to set up a few components and configure them correctly. Here's a step-by-step guide: Prerequisites
- Zabbix Server and Agent: Ensure that your Zabbix server and Zabbix agents are installed and running.
- verify zabbit-server and zabbit-agent is running
$ systemctl status zabbix-server zabbix-agent
- MongoDB Replica Set: Ensure that your MongoDB replica set is configured and operational.
- veify replication status
alexlai@opi58G:~/Downloads$ ssh redisMongo03.yushei.com.tw alexlai@YuShei-Parking-System-API:~$ mongo MongoDB shell version v5.0.8 ... ys20220318:PRIMARY> use admin switched to db admin ys20220318:PRIMARY> db.auth("siteRootAdmin", "b23258585") 1 ys20220318:PRIMARY> rs.conf() { "_id" : "ys20220318", "version" : 22, "term" : 44, "members" : [ { "_id" : 2, "host" : "redisMongo03.yushei.com.tw:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : NumberLong(0), "votes" : 1 }, { "_id" : 6, "host" : "redisMongo04.yushei.com.tw:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : NumberLong(0), "votes" : 1 }, { "_id" : 7, "host" : "redisMongo05.yushei.com.tw:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : NumberLong(0), "votes" : 1 } ], "protocolVersion" : NumberLong(1), "writeConcernMajorityJournalDefault" : true, "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : -1, "catchUpTakeoverDelayMillis" : 30000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("6273a5ccfd0d404b7ca82033") } } ys20220318:PRIMARY> ```
Step-by-Step Guide
- Install MongoDB Monitoring Scripts
There are several scripts and templates available for monitoring MongoDB with Zabbix. One popular choice is the mongodb-zabbix script available on GitHub.
Download the monitoring scripts from the [mongodb-zabbix GitHub repository](https://github.com/omni-lchen/zabbix-mongodb).
bash
cd /opt git clone https://github.com/vvondra/mongodb-zabbix.git
- Configure the MongoDB User for Monitoring
Create a MongoDB user with the necessary permissions for monitoring.
bash
use admin db.createUser({ user: "zabbix", pwd: "zabbixpassword", roles: [ { role: "readAnyDatabase", db: "admin" }, { role: "clusterMonitor", db: "admin" } ] })
- Configure Zabbix Agent on MongoDB Servers
Ensure that the Zabbix agent is installed on all MongoDB replica set members.
Edit the Zabbix agent configuration file (zabbix_agentd.conf) to include the MongoDB monitoring script.
ini
UserParameter=mongo.ping[],/opt/mongodb-zabbix/scripts/mongo_ping.sh $1 UserParameter=mongo.replicationLag[],/opt/mongodb-zabbix/scripts/mongo_replication_lag.sh $1 UserParameter=mongo.replicationState[*],/opt/mongodb-zabbix/scripts/mongo_replication_state.sh $1
Add other parameters as needed
Restart the Zabbix agent service.
bash
sudo systemctl restart zabbix-agent
-
Import Zabbix Template
Download the Zabbix template from the mongodb-zabbix repository. Log in to the Zabbix web interface. Go to Configuration > Templates. Click on Import in the top right corner. Choose the template file you downloaded and import it.
-
Link the Template to MongoDB Hosts
Go to Configuration > Hosts. Select the MongoDB host you want to monitor. Click on Templates. Link the MongoDB template you imported. Save the configuration.
-
Verify Data Collection
After configuring the template, wait for some time to see if data is being collected. Go to Monitoring > Latest data. Check the metrics to see if MongoDB-related data is appearing.
Additional Monitoring and Alerts
To monitor specific metrics and set up alerts for your MongoDB replica set:
Monitoring Replica Set Status: The scripts include checks for replica set status, replication lag, and member state. You can configure triggers in Zabbix to alert you based on these metrics.
Custom Checks: Modify or add custom scripts to monitor additional MongoDB parameters as needed.
Example: Setting up a Trigger
To set up a trigger for MongoDB replication lag:
Go to Configuration > Hosts.
Select the MongoDB host.
Go to the Triggers tab.
Click on Create trigger.
Define the trigger expression, for example:
plaintext
{Template_MongoDB:mongo.replicationLag[localhost].last()} > 1000
Set the severity and other options.
Click on Add to create the trigger.
This guide should help you set up monitoring for a MongoDB replica set in Zabbix. You can customize the monitoring scripts and Zabbix templates further to suit your specific requirements. ChatGPT can make mistakes. Check important info.