ActiveMQ监控脚本
#!/bin/sh
export JAVA_HOME=/usr/local/jdk1.6.0_11
DATE=<code>date+%Y%m%d%H</code>
# get the pid of the activeMQ in your system. the activeMQ port is 61616
PidofAMQ=<code>netstat -tulpen|grep:61616|awk'{print $9}'|awk-F/'{print $1}'</code>
# check the jvm parameter of the activemq, if the olg generation ratio is more than 81%,
# it should have the JVM clean up issue, we should also restart it.
jvmOld=<code>jstat-gcutil$PidofAMQ |awk'{if(NR==2) print $4}'|awk-F"."'{print $1}'</code>
echo$jvmOld# go to the example directory
cd/usr/local/apache-activemq-5.2.0/example
# start the consumer
nohup/usr/bin/ant consumer-Durl=tcp://192.168.100.94:61616 -Dmax=0 -Dreceive-time-out=20000 -Dtopic=true -Dsubject="COF-activemq-testing" > activemq_monitor_result.log 2>&1 &
# sleep 5 seconds to let the consumer started
sleep5;
# start the producer
/usr/bin/ant producer-Durl=tcp://192.168.100.94:61616 -Dtopic=true -Dmax=1 -Dsubject="COF-activemq-testing"
sleep15
#sync the log to disk
sync
# check whether the consumer get the message by Key "Received" status=<code>egrep -o "Received" activemq_monitor_result.log</code>
echo${status}hello
if[$status=="Received"]
then
#check the jvm issue, if old generation is bigger than 81%, dump the jvm and restart it
# send email to system admin
if[$jvmOld-gt81]
then
echo"activeMQ jvm old memory have problems, try to restart it ............"
jstack $PidofAMQ > /tmp/jvm.activemq.log.<code>date+%Y%m%d</code> 2>&1
mutt -s"ActiveMQ jvm thread dump[$DATE]" your_email_address </tmp/jvm.activemq.log.<code>date+%Y%m%d</code>
cat /dev/null > /usr/local/apache-activemq-5.2.0/bin/nohup.out
PidofAMQ=<code>netstat -tulpen|grep:61616|awk'{print $9}'|awk-F/'{print $1}'</code>
/bin/kill -9$PidofAMQ
sleep 3
/bin/kill -9$PidofAMQ
cd /usr/local/apache-activemq-5.2.0/bin/
/usr/bin/nohup sh activemq &
echo"activeMQ restarted" else
echo"activeMQ status and jvm old memory is good"
break;
fi
# can not get the message sent from producer by consumer, restart the activemq server
else
echo"activeMQ status have problems, try to restart it ............"
jstack $PidofAMQ > /tmp/jvm.activemq.log.<code>date+%Y%m%d</code> 2>&1
mutt -s"ActiveMQ jvm thread dump[$DATE]" your_email_address </tmp/jvm.activemq.log.<code>date+%Y%m%d</code>
cat /dev/null > /usr/local/apache-activemq-5.2.0/bin/nohup.out
PidofAMQ=<code>netstat -tulpen|grep:61616|awk'{print $9}'|awk-F/'{print $1}'</code>
/bin/kill -9$PidofAMQ
sleep 3
/bin/kill -9$PidofAMQ
cd /usr/local/apache-activemq-5.2.0/bin/
/usr/bin/nohup sh activemq &
echo"activeMQ restarted"
fi
相关推荐
胡献根 2020-07-18
胡献根 2020-07-05
jiangtie 2020-06-10
onlylixiaobei 2020-06-09
xinglun 2020-06-02
方新德 2020-05-31
Java高知 2020-05-20
Java高知 2020-05-08
Java高知 2020-05-03
onlylixiaobei 2020-05-02
Java高知 2020-04-22
胡献根 2020-04-22
heweiyabeijing 2020-04-21
方新德 2020-04-20
胡献根 2020-04-10
onlylixiaobei 2020-04-10
方新德 2020-04-08
xuedabao 2020-03-30