Sunday, September 27, 2009

Monitoring ActiveMQ with Monit on Debian

Monit is a nice tool for monitoring processes.  I know it's widely used in the RoR environment to monitor Mongrel's that goes nutz and eat too much memory.  It's really easy to setup and configure.  You don't need to be too much in systems administration to handle it, so it's a good tool.

ActiveMQ is something not that light.  But this is one of the most powerful and free messaging providers.

Debian is Linux. :)

Okay, so I'll tell you how you can monitor ActiveMQ with Monit.  It's pretty easy, but we should start with a few tweaks of run scripts for ActiveMQ first.  In my specific setup I have ActiveMQ based at /usr/local/apache-activemq-5.2.0 and the platform is Debian Linux.  It's actually running a Xen-based server on Slicehost which I am very happy about, but that's a different story. 

What I am using to manage ActiveMQ is script /usr/local/apache-activemq-5.2.0/bin/linux-x86-64/activemq.  

# /usr/local/apache-activemq-5.2.0/bin/linux-x86-64/activemq 
Usage: /usr/local/apache-activemq-5.2.0/bin/linux-x86-64/activemq { console | start | stop | restart | status | dump }

You probably mention that I'm using the ...-x86-64 one.  There is also a ...-x86-32 and macosx here, which you can use accordingly for your platform (run uname -a to figure this if you're not sure, although you might not be the right guy to set it up if it's so).

Whatever, first of all I had to modify the first lines of /usr/local/apache-activemq-5.2.0/bin/linux-x86-64/wrapper.conf

set.default.ACTIVEMQ_HOME=/usr/local/apache-activemq-5.2.0/
set.default.ACTIVEMQ_BASE=/usr/local/apache-activemq-5.2.0/

There also many other things you can adjust there, but that's your own business.

After that, you can use /usr/local/apache-activemq-5.2.0/bin/linux-x86-64/activemq to start and stop broker.  You might also want to run activemq console at the first time to see all the logs and messages that are coming to console, to confirm that everything works just fine.  If you're using a server with a limited amount of memory available, make sure to adjust -Xmx setting, it can be done at wrapper.conf:

wrapper.java.maxmemory=128

Now time to modify Monit config file a little bit.  I'll edit /etc/monit/monitrc:

check process activemq
    with pidfile /usr/local/apache-activemq-5.2.0/bin/linux-x86-64/ActiveMQ.pid
    start program = "/usr/local/apache-activemq-5.2.0/bin/linux-x86-64/activemq start"
    stop program = "/usr/local/apache-activemq-5.2.0/bin/linux-x86-64/activemq stop"
    if failed host 127.0.0.1 port 61616 then restart                    

The 61616 port is ActiveMQ default one.  It safe to monitor it, as if it doesn't work, something is wrong.  Basically that's it.  Make sure to reload Monit  to load new configuration file and that's it - you're not afraid of restarts anymore.

# Posted via email from opportunity__cost