您的位置:首页 > 运维架构 > Shell

服务进程和流量检测,web界面检查(shell)

2017-09-29 00:00 176 查看
摘要: 服务进程和流量检测,web界面检查(shell)

#!/bin/bash
export base_dir=`pwd`
export IP=`ifconfig|grep "inet addr:"|awk '{print $2}'|head -n 1|awk -F ":" '{print $2}'`
export time=`date +"%Y%m%d%H%M"`
chechpr(){
#判断服务进程是否存在
pid=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`
if [ $? -eq 0 ];then
if [ -n "$pid" ];then
echo "tomcat is alived"
else
echo "tomcat service is not running!">>/$base_dir/$IP\_$time.log
fi
else
echo "ps command run failed!!!">>/$base_dir/$IP\_$time.log
exit 1
fi
#服务流量监测,是否有tcp连接进入
port=`netstat -antp|grep "ESTABLISHED"|grep "8080"`
if [ $? -eq 1 ];then
if [ -s "$port" ];then
echo "tomcat is alived"
else
echo "tomcat is not tcp conncent ">>/$base_dir/$IP\_$time.log
fi
else
echo "netstat command run failed!!!">>/$base_dir/$IP\_$time.log
exit 1
fi
#监测web界面是否正常;
curl "http://x.x.x.x:8080"
if [ $? -eq 0 ];then
echo "web is ok"
else
echo "web is can not conncent!!!">>/$base_dir/$IP\_$time.log
fi
}
checkfile(){
#如果服务进程异常,将相关信息cp到跳板机对应日期目录下面。
cd /$base_dir
if [ $? -eq 0 ];then
if [ -n "$IP\_$time.log" ];then
date=`date +%Y%m%d`
scp $IP\_$time.log root@x.x.x.x:/home/$date/
if [ $? -eq 0 ];then
echo "scp is ok"
else
echo "scp command run failed"
mail -s "scp command run failed" xxxxxxx@qq.com < /$base_dir/$IP\_$time.log
fi
else
echo "service is ok"
fi
else
echo "cd command run failed">>/$base_dir/$IP\_$time.log
exit 1
fi
}
chechpr
checkfile
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: