Mongodb 监控脚本

工作中遇到mgondb经常因为内存不够宕机,影响业务,特编写此脚本。

#!/bin/bash
#检查是否是root用户

if [ $(id -u) != "0" ]
then
    echo "Not the root user! Try using sudo command!"
    exit 1
fi
     #监控服务是是否存活,这里是通过监控端口来监控服务,这里也可以替换为其他服务
port=`netstat -nlt | grep 27017|wc -l`
if [ $port -ne 1 ]
then
    systemctl start mongod.service
    echo $(date +%T%n%F)" Restart mongodb Services " >> /sh/mongodb.log
else
    echo "mongodb is rumming" 
fi
原文地址:https://www.cnblogs.com/hnsya/p/14862155.html