服务状态检测脚本

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

es_port=9200
rs_port_1=6379
rs_port_2=6380
rs_cluster_1=16379
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

#进程检测
function process(){
    ps -efl | grep -i 1 | grep -v grep|wc -l
}
function processt(){
    ps -efl | grep -i1 | grep -v grep| awk   '{print 4}'| sed -n '1p'
}
#端口检测
function port(){
    netstat -an | grep1 | grep LISTEN | wc -l
}

#获取ip地址
ip=`ip add | grep 192.168 | awk '{print 2}'| cut -d "/" -f1`
#es集群服务检测
es_url=`curl -sXGET  http://{ip}:{es_port}/_cluster/health/?pretty | grep status| awk -F '"' '{print4}'`
#redis集群检测
rs_cluster_status=`/home/tfd/app/redis/bin/redis-cli -h ip -prs_port_1 -c cluster info| grep cluster_state | awk -F ':' '{print 2}'`
#ignite集群检测
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}' `
#web检测定义
function web_url(){
    wget --spider -q http://{ip}:{1}/{2}
}

function es(){
    if [ `process ela` -eq 0 ];then
        echo ip服务器es服务未启动
    elif [ `portes_port` -ne 0 ] && [ "es_url" == "green" ] ;then
        echo es服务正常
        echo es集群状态正常es_url
    else
        echo 未检测到`processt ela`进程的端口,请及时排查
        echo es集群状态异常es_url
fi
}
#redis节点1检测
function rs_one(){
    if [ `process redis` -eq 0 ];then
        echoip服务器redis服务未启动
    elif [ `port rs_port_1` -ne 0 ];then
        echo redis节点1服务正常
    else
        echo 未检测到`processt redis`进程的端口,请及时排查
fi
}
#redis节点2检测
function rs_two(){
    if [ `process redis` -eq 0 ];then
        echoip服务器redis服务未启动
    elif [ `port rs_port_2` -ne 0 ];then
        echo redis节点2服务正常
    else
        echo 未检测到`processt redis`进程的端口,请及时排查
fi
}
#redis集群状态检测
function rs_status(){
    if [ "rs_cluster_status" == "ok" ];then
        echo redis集群状态正常rs_cluster_status
    else
        echo redis集群状态异常rs_cluster_status
fi
}
#zookeeper服务检测
function zk(){
    if [ `process zookeeper` -eq 0 ];then
        echo ip服务器zookeeper服务未启动
    elif [ `portzk_port` -ne 0 ];then
        echo zk服务正常
    else
        echo 未检测到`processt zookeeper`进程的端口,请及时排查
fi
}
#kafka服务检测
function ka(){
    if [ `process kafka` -eq 0 ];then
        echo ip服务器kafka服务未启动
    elif [ `portka_port` -ne 0 ];then
        echo kafka服务正常
    else
        echo 未检测到`processt kafka`进程的端口,请及时排查
fi
}
#ignite检测
function ig(){
    if [ `process ignite` -eq 0 ];then
        echo ip服务器ignite服务未启动
    elif [ `portig_port` -ne 0 ];then
        echo ignite服务正常
        echo ignite集群状态正常ig_url
        echo ignite在线节点数ig_nodes_url
    else
        echo 未检测到`processt ignite`进程的端口,请及时排查
fi
}
#mysql检测
function my(){
    if [ `process mysql` -eq 0 ];then
        echo ip服务器mysql服务未启动
    elif [ `portmy_port` -ne 0 ];then
        echo mysql服务正常
    else
        echo 未检测到`processt mysql`进程的端口,请及时排查
fi
}
#did进程检测
function did(){
    if [ `process /home/tfd/app/did` -eq 0 ];then
        echo ip服务器did服务未启动
    web_urldid_port did
    elif [ `port did_port` -ne 0 ] && [? -eq 0 ] ;then
        echo did服务正常
    else
        echo 未检测到`processt /home/tfd/app/did`进程的端口,请及时排查
        echo did服务异常
fi      
}

function admin(){
    if [ `process admin` -eq 0 ];then
        echo ip服务器admin服务未启动
    web_urladmin_port thunder-admin
    elif [ `port admin_port` -ne 0 ] && [? -eq 0 ]  ;then
        echo admin服务正常
    else
        echo 未检测到`processt admin`进程的端口,请及时排查
        echo admin服务异常
fi
}
function api(){
    if [ `process thunder-api` -eq 0 ];then
        echo ip服务器api服务未启动
    web_urlapi_port thunder-api
    elif [ `port api_port` -ne 0 ] && [? -eq 0 ] ;then
        echo api服务正常
    else
        echo 未检测到`processt thunder-api`进程的端口,请及时排查
        echo api服务异常            
fi
}
function con(){
    if [ `process consumer` -eq 0 ];then
        echo ip服务器consumer服务未启动
    else
        echoip服务器consumer进程运行正常,进程号:`processt consumer`
fi
}
main(){
    es
    rs_one
    rs_two
    rs_status
    zk
    ka
    ig
    my
    did
    admin
    api
    con
}
main


THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭