Monitor CPU usage for multi-instance Tomcat

Source: Internet
Author: User


Demand:

Monitoring Top life Today, Tomcat process%CPU time accounted for more than 80% times to kill the process, and then restart the pair should be Tomcat, and record the reboot of the Tomcat, as well as the restart time of the log

#!/bin/bash# Print tomcatid number #tomcatid= ' Ps-ef |grep tomcat|grep-w ' tomcat ' |grep-v Grep|awk ' {print $ {} ' tomcatid= ' JPS |grep Bootstrap|awk ' {print '} ' datetime= ' (date ' +%f%h:%m:%s ') '  #获取单前时间LOG =/tmp/tomcat.log  #日志文件if [!-N ' $ Tomcatid "];then    echo" please start Tomcat. "#判断pid是否为空else for   i in $tomcatid;d o    tomcatdir= ' ps aux|grep $i | awk ' {for (i=1;i<nf;i++) if ($i ~/dcatalina\.home/) Print $i} ' |awk-f ' = ' {print $} ' |head-1 ' #获取tomcat的catalina home Path     if ["$i"];then        echo "The Tomcat is starting. PID: $i. Tomcatdir: $tomcatdir "#通过pid判断tomcat是否启动; started judging cpu        cpu= ' top-bn1 |grep" $i "| awk ' {print $9} ' |cut-d '."-f1 " c8/>if [$cpu-lt];then             kill-9 "$i"             sleep 3            "$tomcatdir/bin/startup.sh"             echo "the  Tomcat Pid: $i   Restart Tomcat time $DATETIME ">> $LOG           fi      fi   donefi~



This article is from the "Time Still Wipe" blog, please be sure to keep this source http://xulianglinux.blog.51cto.com/8001428/1775388

Monitor CPU usage for multi-instance Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.