定时抓取服务器状态

作者: 操作系统  发布:2019-09-06

首先个 定期抓取服务器JVM相关新闻
#! /bin/sh #get_current_time export JAVA_HOME=/opt/jdk1.6.0_10/export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH date=`date "+%Y-%m-%d-%H:%M:%S"` Root="/data/dxm/" jmapends=$Root$date"_jmap.txt"jstackends=$Root$date"_jstack.txt" jstateends=$Root$date"_jstate.txt" #start to register the jmap message echo "start to register the jmap to "$jmapends jmap -histo:live `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jmapends sleep 2 #start to register the jtack message echo "start to register the jstack to "$jstackends jstack -l `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jstackends sleep 2 #start to register the jstate message echo "start to register the jstate message to "$jstateends jstat -gcutil -t -h20 `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` 1000 20 > $jstateends
 
本条能够跑个计时器:
crontab -e
*/10 * * * * sh /timer/timer.sh  #每拾贰分钟抓一遍
 
其次个本子:对地点的台本创新一下,只有系统负荷到达钦赐的值之后才打字与印刷JVM新闻
Java代码
#! /bin/sh       function printJVMMessage() {     #get_current_time   export JAVA_HOME=/opt/jdk1.6.0_10/   export PATH=$JAVA_HOME/bin:$PATH   export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH     #only the system load greate than 1*8PU then start to print the gc details       date=`date "+%Y-%m-%d-%H:%M:%S"`     Root="/data/dxm/"      jmapends=$Root$date"_jmap.txt"  jstackends=$Root$date"_jstack.txt"  jstateends=$Root$date"_jstate.txt"      #start to register the jmap message   echo "start to register the jmap to "$jmapends   jmap -histo:live `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jmapends     sleep 2    #start to register the jtack message   echo "start to register the jstack to "$jstackends   jstack -l `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jstackends     sleep 2    #start to register the jstate message   echo "start to register the jstate message to "$jstateends   jstat -gcutil -t -h20 `jps|grep Resin |awk 'NR==1'|awk '{print $1}'`  1000 20 > $jstateends     }       #System Max Load Per CPU,when the SystemLoad reached the MAX_LOAD * CPU_NUMBER then start register the jvm message   MAX_LOAD=1    CPU_NUMBER=`cat /proc/cpuinfo | grep processor |wc -l`     <STRONG style="BACKGROUND-COLOR: #ffffff"><SPAN style="COLOR: #ff0000">TOTAL_LOAD_TO_WARN</SPAN></STRONG>=$(($MAX_LOAD*$CPU_NUMBER))   #TOTAL_LOAD_TO_WARN=1    CURRENT_SYSTEM_LOAD=`uptime | awk '{print $(NF-2)}' | sed 's/,//'`     Start_Time=`date "+%Y-%m-%d-%H:%M:%S"`     echo 'start to print the jvm message...currenttime is:'$Start_Time   echo 'current system load is'$CURRENT_SYSTEM_LOAD' and TOTAO_LOAD_TO_WARN is '$TOTAL_LOAD_TO_WARN     if [ $(echo "$CURRENT_SYSTEM_LOAD > $TOTAL_LOAD_TO_WARN"|bc) == 1 ]; then       echo 'printint the jvm message...'      printJVMMessage   fi     Finish_Time=`date "+%Y-%m-%d-%H:%M:%S"`   echo 'finish to print the jvm message...and current time is:'$Finish_Time 
#! /bin/sh function printJVMMessage() {#get_current_timeexport JAVA_HOME=/opt/jdk1.6.0_10/ export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH #only the system load greate than 1*8PU then start to print the gc details date=`date "+%Y-%m-%d-%H:%M:%S"`Root="/data/dxm/"jmapends=$Root$date"_jmap.txt" jstackends=$Root$date"_jstack.txt"jstateends=$Root$date"_jstate.txt" #start to register the jmap message echo "start to register the jmap to "$jmapends jmap -histo:live `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jmapends sleep 2#start to register the jtack message echo "start to register the jstack to "$jstackends jstack -l `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jstackendssleep 2 #start to register the jstate message echo "start to register the jstate message to "$jstateends jstat -gcutil -t -h20 `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` 1000 20 > $jstateends } #System Max Load Per CPU,when the SystemLoad reached the MAX_LOAD * CPU_NUMBER then start register the jvm message MAX_LOAD=1CPU_NUMBER=`cat /proc/cpuinfo | grep processor |wc -l` TOTAL_LOAD_TO_WARN=$(($MAX_LOAD*$CPU_NUMBER)) #TOTAL_LOAD_TO_WARN=1 CURRENT_SYSTEM_LOAD=`uptime | awk '{print $(NF-2)}' | sed 's/,//'` Start_Time=`date "+%Y-%m-%d-%H:%M:%S"` echo 'start to print the jvm message...currenttime is:'$Start_Time echo 'current system load is'$CURRENT_SYSTEM_LOAD' and TOTAO_LOAD_TO_WARN is '$TOTAL_LOAD_TO_WARN if [ $(echo "$CURRENT_SYSTEM_LOAD > $TOTAL_LOAD_TO_WARN"|bc) == 1 ]; then echo 'printint the jvm message...' printJVMMessagefi Finish_Time=`date "+%Y-%m-%d-%H:%M:%S"` echo 'finish to print the jvm message...and current time is:'$Finish_Time
 
 
 
其八个剧本:比比较多少个版本中jar包是不是一律(有改观):
#! /bin/sh #compare the lib files's md5 int file1 with those in file2 #if it only exist in file1 or one lib file's md5 is not equal i #with the other then print it to the log.txt LibPath1=$1LibPath2=$2 date=`date "+%Y-%m-%d-%H:%M:%S"` LOG=$date"_log.txt" echo "-----------log file " $LOG echo LibPath1: $LibPath1 echo LibPath2: $LibPath2echo LibPath1: $LibPath1 n >> $LOG echo LibPath2: $LibPath2 n >> $LOGecho >> $LOGecho >> $LOG for File in `ls -f $LibPath1|grep jar `;do MD5=`md5sum $1$File |awk 'NR==1'|awk '{print $1}'` File2=$LibPath2$File #echo "File2-----------------" $File2 #if the same lib file exist if [ ! -f "$File2" ]; then echo $File only exist LibPath1 echo $File only exist LibPath1 n >> $LOG echo >> $LOG #if the same file exist in directory2 else MD52=`md5sum $File2 |awk 'NR==1'|awk '{print $1}'` if [ "$MD5" != "$MD52" ]; then echo the $File changed n >> $LOG echo >> $LOG echo the $File changed fi fi done  上的充裕文件为md5compare.sh 运营是能够用以下命令运营: ./md5compare.sh libpath1 libpath2在意libpath1,libpath2 必得以"/" 结尾举例:/opt/ROOT_2011-09-08-09:57:26/WEB-INF/lib/而不是/opt /ROOT_2011-09-08-09:57:26/WEB-INF/lib]]]

#! /bin/sh
 
#get_current_time 特别注意以下多少个必得手动引出,手动实行时和在crontab -e 中进行中景况不相同
export JAVA_HOME=/opt/jdk1.6.0_10/
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
 
date=`date "+%Y-%m-%d-%H:%M:%S"`
 
Root="/data/dxm/"
 
 
jmapends=$Root$date"_jmap.txt"
jstackends=$Root$date"_jstack.txt"
jstateends=$Root$date"_jstate.txt"
 
 
 
 
 
#start to register the jmap message
echo "start to register the jmap to "$jmapends
jmap -histo:live `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jmapends
 
sleep 2
 
#start to register the jtack message
echo "start to register the jstack to "$jstackends
jstack -l `jps|grep Resin |awk 'NR==1'|awk '{print $1}'` > $jstackends
 
sleep 2
 
#start to register the jstate message
echo "start to register the jstate message to "$jstateends
jstat -gcutil -t -h20 `jps|grep Resin |awk 'NR==1'|awk '{print $1}'`  1000 20 > $jstateends

作者“sky-鹏”

 

定期抓取服务器JVM相关音讯 #! /bin/sh #get_current_time export JAVA_HOME=/opt/jdk1.6.0_10/export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/too...

小编“狼之梦---爱乌及屋”  

本文由今晚买四不像发布于操作系统,转载请注明出处:定时抓取服务器状态

关键词: