美文网首页
巡检脚本

巡检脚本

作者: 白纸糊 | 来源:发表于2020-01-07 09:13 被阅读0次
    #!/bin/bash
    time=`date "+%Y-%m-%d %H:%M:%S"`
    hostname=`hostname`
    total=`free -h | awk 'NR==2{print $2}'`
    used=`free -h | awk 'NR==2{print $3}'`
    hosts="1 2 3"
    cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $8}'|cut -f 1 -d "."`
    cpu_use=`expr 100 - $cpu_idle`
    
    
    echo "====================CPU==Memory===================="
    
    echo  $time $hostname
    echo "CPU 使用率:${cpu_use}%  CPU空闲:${cpu_idle}%"
    echo "总内存$total,已使用内存$used"
    
    echo "====================jar============================"
    
    jars="sbsx-auth.jar sbsx-config.jar sbsx-daemon.jar sbsx-eureka.jar sbsx-gateway.jar sbsx-upms-biz.jar sunsmd-business.jar sunsmd-third.jar"
    
    for jar in $jars;
    
    do
      NR=`ps -ef |grep ${jar} |grep -v "grep" | wc -l`
      if [ "$NR" -eq 1 ];
      then
            echo "$jar 运行正常!"
      else
            echo "$jar 服务异常,请检查!!!"
      fi
    done
    
    for host in $hosts
    do
    echo "---------------------------------------------------------"
    echo -e "\n"|telnet $host 6379|grep Connected > /dev/null 2>&1
    if [ $? -eq 0 ];
    then
    echo "$host Redis service is ok!"
    else
    echo "$host Redis service is down!!!"
    fi
    
    echo -e "\n"|telnet $host 2181|grep Connected > /dev/null 2>&1
    if [ $? -eq 0 ];
    then
    echo "$host Zookeeper service is ok!"
    else
    echo "$host Zookeeper service is down!!!"
    fi
    
    echo -e "\n"|telnet $host 8848|grep Connected > /dev/null 2>&1
    if [ $? -eq 0 ];
    then
    echo "$host eureka  service is ok!"
    else
    echo "$host eureka  service is down!!!"
    fi
    
    echo "---------------------------------------------------------"
    done
    
    

    相关文章

      网友评论

          本文标题:巡检脚本

          本文链接:https://www.haomeiwen.com/subject/judooctx.html