#!/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
sleep
5
;
# start the producer
/
usr
/
bin
/
ant
producer
-
Durl
=
tcp
:
//192.168.100.94:61616 -Dtopic=true -Dmax=1 -Dsubject="COF-activemq-testing"
sleep
15
#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
-
gt
81
]
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