服务状态检测脚本

端口可改成项目上的端口

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#获取ip地址
ip=`ip add | grep 192.168 | awk '{print 2}'| cut -d "/" -f1`
#es端口
es_port=9200
rs_port_1=6379
rs_cluster_1=16379
rs_port_2=6380
rs_cluster_2=16380
zk_port=2181
ka_port=9092
ig_port=47500
my_port=3306
did_port=8080
admin_port=8080
api_port=8081

#es服务检测
es_process=`ps -efl | grep ela  | grep -v grep| awk   '{print4}'| sed -n '1p'`
es_port_status=`netstat -an | grep es_port | grep LISTEN | awk -F ':' '{print2}'`

if [ ! -n "es_process" ];then
    echoip服务器es服务未启动
elif [ "es_process" != 0 ] && [ "es_port_status" -eq es_port ];then
    echo es服务正常
elif [ "es_process" != 0 ]  || [ "es_port_status" -eqes_port ];then
    echo 未检测到es_process进程对应的端口,请及时排查

fi
#es集群检测
es_url=`curl -sXGET  http://{ip}:{es_port}/_cluster/health/?pretty | grep status| awk -F '"' '{print4}'`
if [ "es_url" == "green" ];then
    echo es集群状态正常es_url
else
    echo es集群状态异常es_url
fi

#redis服务检测
rs_process_1=`ps -efl | greprs_port_1  | grep -v grep| awk   '{print 4}'`
rs_process_2=`ps -efl | greprs_port_2  | grep -v grep| awk   '{print 4}'`
rs_port_status_1=`netstat -an | greprs_port_1 | grep -v rs_cluster_1  | grep LISTEN | awk -F ':' '{print2}'|cut -d " " -f1| sed -n '1p'`
rs_port_status_2=`netstat -an | grep rs_port_2  |grep -vrs_cluster_2 | grep LISTEN | awk -F ':' '{print 2}'|cut -d " " -f1| sed -n '1p'`

if [ ! -n "rs_process_1" ];then
    echo ip服务器redis节点1服务未启动
elif [ "rs_process_1" != 0 ] && [ rs_port_status_1 -eq "rs_port_1" ];then
    echo redis节点1服务正常
elif [ "rs_process_1" != 0 ]  || [ "rs_port_status_1" -eq rs_port_1 ];then
    echo 节点1未检测到rs_process_1进程对应的端口,请及时排查
fi

if [ ! -n "rs_process_2" ];then
    echoip服务器redis节点2服务未启动
elif [ "rs_process_2" != 0 ] && [rs_port_status_2 -eq rs_port_2 ];then
    echo redis节点2服务正常
elif [ "rs_process_2" != 0 ]  || [ "rs_port_status_2" -eqrs_port_2 ];then
    echo 节点2未检测到rs_process_2进程对应的端口,请及时排查
fi
#redis集群状态
rs_cluster_status=`/home/tfd/app/redis/bin/redis-cli -hip -p rs_port_1 -c cluster info| grep cluster_state | awk -F ':' '{print2}'`
if [ "rs_cluster_status" == "ok" ];then
    echo redis集群状态正常rs_cluster_status
else
    echo redis集群状态异常rs_cluster_status
fi

#zk服务检测
zk_process=`ps -efl | grep zookeeper  | grep -v grep| awk   '{print4}'| sed -n '1p'`
zk_port_status=`netstat -an | grep zk_port | grep LISTEN | awk -F ':::' '{print2}'`

if [ ! -n "zk_process" ];then
    echoip服务器zk服务未启动
elif [ "zk_process" != 0 ] && [zk_port_status -eq zk_port ];then
    echo zk服务正常
elif [ "zk_process" != 0 ]  || [ "zk_port_status" -eqzk_port ];then
    echo 未检测到zk_process进程对应的端口,请及时排查
fi
#zk集群状态
#zk_cluster_status=`/home/tfd/app/zookeeper/bin/zkServer.sh status | grep Mode| awk -F ':' '{print2}'`

#kafka服务检测
ka_process=`ps -efl | grep kafka  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
ka_port_status=`netstat -an | grepka_port | grep LISTEN | awk -F ':' '{print 2}'`
if [ ! -n "ka_process" ];then
    echo ip服务器kafka服务未启动
elif [ "ka_process" != 0 ] && [ ka_port_status -eqka_port ];then
    echo kafka服务正常
elif [ "ka_process" != 0 ]  || [ "ka_port_status" -eq kafka_port ];then
    echo 未检测到ka_process进程对应的端口,请及时排查
fi

#ignite服务检测
ig_process=`ps -efl | grep ignite  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
ig_port_status=`netstat -an | grepig_port | grep LISTEN | awk -F ':::' '{print 2}'`
ig_url=`/home/tfd/app/ignite/bin/control.sh --baseline | grep state | awk '{print3}' `
ig_nodes_url=`/home/tfd/app/ignite/bin/control.sh --baseline | grep "baseline nodes" | awk -F ':' '{print 2}' `
if [ ! -n "ig_process" ];then
    echo ip服务器ignite服务未启动
elif [ "ig_process" != 0 ] && [ "ig_port_status" -eqig_port ];then
    echo ignite服务正常
    echo ignite集群状态正常ig_url
    echo ignite在线节点数ig_nodes_url
elif [ "ig_process" != 0 ]  || [ "ig_port_status" -eq ig_port ];then
    echo 未检测到ig_process进程对应的端口,请及时排查
fi

#mysql服务检测
my_process=`ps -efl | grep -i mysql  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
my_port_status=`netstat -an | grepmy_port | grep LISTEN | awk -F ':::' '{print 2}'`

if [ ! -n "my_process" ];then
    echo ip服务器mysql服务未启动
elif [ "my_process" != 0 ] && [ "my_port_status" -eqmy_port ];then
    echo mysql服务正常
elif [ "my_process" != 0 ]  || [ "my_port_status" -eq my_port ];then
    echo 未检测到my_process进程对应的端口,请及时排查
fi

#did服务检测
did_process=`ps -efl | grep -i /home/tfd/app/did  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
did_port_status=`netstat -an | grepdid_port | grep LISTEN | awk -F ':::' '{print 2}'`

if [ ! -n "did_process" ];then
    echo ip服务器did服务未启动
elif [ "did_process" != 0 ] && [ "did_port_status" -eqdid_port ];then
    echo did服务正常
elif [ "did_process" != 0 ]  || [ "did_port_status" -eq did_port ];then
    echo 未检测到did_process进程对应的端口,请及时排查
fi

#admin进程检测
admin_process=`ps -efl | grep -i admin  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
admin_port_status=`netstat -an | grepadmin_port | grep LISTEN | awk -F ':::' '{print 2}'`

if [ ! -n "admin_process" ];then
    echo ip服务器admin服务未启动
elif [ "admin_process" != 0 ] && [ "admin_port_status" -eqadmin_port ];then
    echo admin进程运行正常
elif [ "admin_process" != 0 ]  || [ "admin_port_status" -eq admin_port ];then
    echo 未检测到admin_process进程对应的端口,请及时排查
fi

#api进程检测
api_process=`ps -efl | grep -i thunder-api  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
api_port_status=`netstat -an | grepapi_port | grep LISTEN | awk -F ':::' '{print 2}'`

if [ ! -n "api_process" ];then
    echo ip服务器api服务未启动
elif [ "api_process" != 0 ] && [ "api_port_status" -eqapi_port ];then
    echo api进程运行正常
elif [ "api_process" != 0 ]  || [ "api_port_status" -eq api_port ];then
    echo 未检测到api_process进程对应的端口,请及时排查
fi

#consumer服务检测
con_process=`ps -efl | grep -i consumer  | grep -v grep| awk   '{print 4}'| sed -n '1p'`
if [ ! -n "con_process" ];then
    echo ip服务器consumer服务未启动
else
    echoip服务器consumer进程运行正常,进程号:$con_process
fi
THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭