How to monitor mongodb replica set using zabbix
- see details from official: https://www.zabbix.com/documentation/3.4/manual/installation/install
install pcre
#### install pcre
mongo*:~ # zypper install gcc gcc-c++
mongo*:~ # wget https://sourceforge.net/projects/pcre/files/pcre/8.42/pcre-8.42.zip
mongo*:~ # unzip pcre-8.42.zip && cd pcre-8.42
mongo*:~ # ./configure && make && make install
install jq
mongo*:~ # wget https://github-production-release-asset-2e65be.s3.amazonaws.com/5101141/65ac1c64-43ac-11e5-9195-46846013b9a3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180708%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180708T090940Z&X-Amz-Expires=300&X-Amz-Signature=335820709df7917e2314624984187b69fd8e3318e93462968e1fbce5dc39cf93&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Djq-linux64&response-content-type=application%2Foctet-stream
mongo*:~ # mv jq-linux64 /usr/sbin/jq && chmod +x /usr/sbin/jq
mongo*:~ # which jq
/usr/sbin/jq
install zabbix agent
mongo*:~ # wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.11/zabbix-3.4.11.tar.gz
mongo*:~ # tar xf zabbix-3.4.11.tar.gz
mongo*:~ # cd zabbix-3.4.11/
mongo*:~ # ./configure --prefix=/usr/local/zabbix --enable-agent
mongo*:~ # make && make install
Medify zabbix agent configure files
mongo*:~ # egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=172.21.0.20
ServerActive=172.21.0.20
Hostname=mongo2
UnsafeUserParameters=1
starting zabbix agent
mongo*:~ # /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
Edit zabbix scripts
Edit the script to get mongodb replica set status
mongo*:~ # mkdir -pv /usr/local/zabbix/script
mongo*:~ # cat /usr/local/zabbix/script/mongodb.sh
DB_HOST=172.21.0.1
DB_PORT=27017
DB_USERNAME=
DB_PASSWORD=
MONGO=`which mongo`
JQ=`which jq`
EXIT_ERROR=1
EXIT_OK=0
if [ ! -x "$MONGO" ] ; then
echo "mongo not found"
exit $EXIT_ERROR
elif [ ! -x "$JQ" ] ; then
echo "jq not found"
exit $EXIT_ERROR
elif [ $# -eq 0 ] ; then
echo "No values pass"
exit $EXIT_ERROR
fi
index=.$(echo $@ | sed 's/[ ,]/./g')
MONGO_CMD="$MONGO --host ${DB_HOST:-localhost} --port ${DB_PORT:-27017} --authenticationDatabase admin --quiet"
[[ "$DB_USERNAME" ]] && MONGO_CMD="${MONGO_CMD} --username ${DB_USERNAME}"
[[ "$DB_PASSWORD" ]] && MONGO_CMD="${MONGO_CMD} --password ${DB_PASSWORD}"
output=$(
$MONGO_CMD <<< "db.runCommand( { serverStatus: 1} )" |\
sed -e 's/NumberLong(\(.*\))/\1/
s/ISODate(\(.*\))/\1/
s/ObjectId(\(.*\))/\1/
s/Timestamp(.*)/"&"/
s/"\([0-9]*\)"/\1/'
)
mongo_status=${PIPESTATUS[0]}
if [ $mongo_status -ne $EXIT_OK ] ; then
echo "mongo exec error"
exit $EXIT_ERROR
fi
value=$(echo $output | jq $index)
jq_status=$?
echo $value
check datasize script
named checkdatasize.sh
#!/bin/bash
du -s $1 | awk '{print $1}'
check mongodb process
named check_mongo_status.sh
#!/bin/bash
ps -ef | grep mongod.conf | grep -v grep | wc -l
Configure Zabbix UserParameter
mongo*:~ # cd /usr/local/zabbix/etc/zabbix_agentd.conf.d
UserParameter=mongodb.status[*],/usr/local/zabbix/script/mongo.sh $1 $2 $3 $4 $5
UserParameter=mongodb.processcheck,/usr/local/zabbix/script/check_mongo_status.sh
UserParameter=mongodb.checkdatasize[*],/usr/local/zabbix/script/checkdatasize.sh $1