codecentric

Monitoring JBoss AS start with JMX

As my colleague Robert described in his article “How to automate OpenCms module import” we set up an automatic deployment process for one of our projects. However, we experienced some trouble with our way to check whether the app server finished starting up. We were using a simple grep command to observe the server log and it sometimes failed for no apparent reason:

until tail -n 1 server.log | grep "Started"; do sleep 0.01; done

We wanted to find a better way for solving this issue. I only overheard the conversation passing by, but I didn’t get it out of my head even after hours …

For we are using a JEE compliant server (JBoss) I wanted to probe JMX for it is the designated monitoring interface. I was about to write a little JMX client that probes the desired MBean, but while fiddling with the issue I came across an even easier solution: JBoss offers a little helper out of the box that is up to the task in no time and saved me a late night coding session. It’s a little tool called twiddle:

JBoss’ description is self-explanatory:

“A JMX client to ‘twiddle’ with a remote JBoss server.”

Just what we needed! Now we only had to decide which MBean to probe. As “are u there?” is one of the most basic things to ask for this wasn’t too hard either:

twiddle.sh get jboss.system:type=Server Started

As soon as this returns true the server is up and running.

Robert immediately pimped our little script accordingly:

function twiddleTheBoss {
    echo `twiddle.sh get "jboss.system:type=Server" Started | \
        awk -F "=" '{ print $2 }'`
}
 
...
 
local STARTED="starting"
until [ $STARTED == "true" ]; do
    sleep 20s
    STARTED=$(twiddleTheBoss)
done
 
...

Easy and reliable, just what we wanted :)

  • Facebook
  • Delicious
  • Digg
  • StumbleUpon
  • Mister Wong
  • Reddit
  • Instapaper
  • Technorati
  • Blogger
Nick Prosch

 

Weitere Beiträge aus dem codecentric Blog

One Response to Monitoring JBoss AS start with JMX

  1. Pietro Aragona says:

    Thanks Nick, this it is very useful for me, I’m looking for it. I’ll try it asap.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">