Script to monitor Health Instance on MongoDB Cluster
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
## ## Script to Monitoring MongoDB Instances on a Cluster ## ## Show Servername and Status on the Cluster ## PHOME=$HOME/scripts/monitor PDATI=`date +%m%d%Y_%H%M%S` PLOGL=$PHOME/logs/mongodbmon_$PDATI.log PLOGE=$PHOME/logs/mongodbmon_$PDATI.err PPASS=PasswdUserWithRootPrivs PUSER=UserWithRootPrivileges PPORT=PortUsed export PHOME PLOGL PLOGE PPASS PUSER PPORT mongo -u$PUSER -p$PPASS --authenticationDatabase 'admin' --port $PPORT --eval 'rs.status()' --quiet > $PLOGL 2> $PLOGE grep "name" $PLOGL | sed 's/\t//g' | sed 's/,//g' | sed 's/"//g' | sed 's/name/Server/g' > $PHOME/temp01.txt grep "stateStr" $PLOGL | sed 's/\t//g' | sed 's/,//g' | sed 's/"//g' | sed 's/stateStr/Status/g' > $PHOME/temp02.txt awk 'FNR==NR { a[FNR""] = $0; next } { print a[FNR""],"-----", $0 }' $PHOME/temp01.txt $PHOME/temp02.txt > $PHOME/tmp.txt echo "Subject: MongoDB Instance Monitoring " | sendmail -v email@companyname.com < $PHOME/tmp.txt rm $PHOME/temp01.txt $PHOME/temp02.txt $PHOME/tmp.txt |
Note: Requires username and password with RootPrivileges.