• tomcat健康检查监控脚本


    #!/bin/sh
    #自动监控tomcat脚本并且执行重启操作
    #获取tomcat_ID
    TomcatID=`ps -ef|grep tomcat|grep -v "grep"|grep -v "monitor_tomcat"|awk '{print $2}'`
    Tomcatbag=`ls /usr/local/apache-tomcat-7.0.42/webapps -t |head -1`
    #tomcat启动程序
      StartTomcat=/home/deployer/scripts/monitor_restart.sh
      TomcatCache=/usr/local/apache-tomcat-7.0.42/work/
    # 定义要监控的页面地址
      #积分 WebUrl=http://127.0.0.1:8080/integral/health/check
      WebUrl=http://127.0.0.1:8080/$Tomcatbag/healthCheck/verify
    # 日志输出
      GetPageInfo=/home/deployer/scripts/monitor_logs/error_$(date +'%F').log
      TomcatMonitorLog=/home/deployer/scripts/monitor_logs/TomcatMonitor_$(date +'%F').log

    Monitor()
        {
          echo "[info]开始监控tomcat...[$(date +'%F %H:%M:%S')]"
          if [[ $TomcatID ]];then
            echo "[info]当前tomcat进程ID为:$TomcatID,检测页面..."
            TomcatServiceCode=$(curl -s -o $GetPageInfo -m 10 --connect-timeout 30 $WebUrl -w %{http_code})
            echo $TomcatServiceCode
            if [ $TomcatServiceCode -eq 200 ];then
                echo "[info]页面返回码为$TomcatServiceCode,tomcat启动成功,测试页面正常......"
            else
                echo "[error]tomcat页面出错,请注意......状态码为$TomcatServiceCode,错误日志已输出到$GetPageInfo"
                echo "[error]页面访问出错,开始重启tomcat"
                kill -9 $TomcatID
                sleep 3
                rm -rf $TomcatCache
                $StartTomcat
            fi
          else
            echo "[error]tomcat进程不存在!tomcat开始自动重启..."
            echo "[info]$StartTomcat,请稍候......"
            rm -rf $TomcatCache
            $StartTomcat
          fi
          echo "------------------------------"
       }

    Monitor>>$TomcatMonitorLog
    cd /home/deployer/scripts/monitor_logs
    find . -maxdepth 2 -mtime +5 -name "*.log" -exec rm -rf {} ;

  • 相关阅读:
    iOS集成ijkplayer视频直播框架,遇到的bug和坑...
    push notification获取device token
    ios xcode Code signing failed 解决方案
    ios 返回指定导航控制器
    ios git 终端提交
    mysql问题集合
    mysql 备份和恢复
    cacti 异常问题
    硬盘各项检测
    LVS DR模式(直接路由模式)
  • 原文地址:https://www.cnblogs.com/franjia/p/6856510.html
Copyright © 2020-2023  润新知