Sunday, February 23, 2014

JBoss monitoring with Twiddle

This short article introduces twiddle, a command line utility to administer a JBoss instance and shows how you can monitor a given instance of JBoss with it through a shell script.

JBoss provides a simple command line tool that allows for interaction with a remote JMX server instance. This tool is called twiddle (for twiddling bits via JMX) and is located in the bin directory of the distribution. Twiddle is a command execution tool, not a general command shell.

The 2 following links show basic usage of twiddle:

All available metrics can be found using the jmx-console deployed by the JBoss instance.

Next, here is a simple shell script that automate the collect of JBoss metrics (free & total memories, active threads count and active sessions count):


# path to the log file (the directory /var/log/jboss must exist. Adapt this path to reflect your needs)
LOGFILE=/var/log/jboss/jbossmon-`hostname`-`date +"%Y%m%d"`.log
echo Logging JBoss metrics to $LOGFILE

# function that uses twiddle to get jboss metrics, given:
#  a first parameter that is the path to the MBean
#  a second parameter that is the name of the attribute of the MBean
# Notice that you may need to adapt the call to twiddle to use authentication or a dedicated port
# e.g: ./ -u user -p password -s jnp://localhost:9099
# Also update the path to the, if this script is not saved in the same directory, i.e the bin directory of the JBoss distribution
function getJbossMetric() {
 ./ get $1 $2 | cut -d'=' -f2

# collects metrics every 5 mn forever (naive approach)
# Notice that a better way would be to replace the loop by a scheduler like cron
until false 
 # collects some metrics within JBoss using twiddle
 FREEMEM=$(getJbossMetric jboss.system:type=ServerInfo FreeMemory)
 TOTALMEM=$(getJbossMetric jboss.system:type=ServerInfo TotalMemory)
 THREADS=$(getJbossMetric jboss.system:type=ServerInfo ActiveThreadCount)
 # NB: you need to update the path property to reflect the context path of your web application
 SESSIONS=$(getJbossMetric jboss.web:host=localhost,path=/contextPathOfMyWebApp,type=Manager activeSessions)

 echo "-------------------------------------"
 echo "Free memory:    $FREEMEM"
 echo "Total memory:   $TOTALMEM"
 echo "Active Threads: $THREADS"
 echo "Sessions:       $SESSIONS"
 echo "-------------------------------------"
 # append metrics to the log file in a CSV manner
 TIMESTAMP=`date +"%d/%m/%Y %T"`

 # waits for 300s (5mn)
 sleep 300
I hope this will be useful to those who want to monitor JBoss in a simple way.


  1. Came across your blog, I see that you really know your Java and Junit. Was wondering if you can help me with creating Junit test cases for some of my code. and

    Your help is greatly appreciated.

    1. Hi Nick. Thank you for your comment. I think that the main difficulty to test your code is to simulate user input with I suggest you to look at this article that deals with that kind of problem: Hope that will help you.

  2. Can Twiddle be invoked externally. E.g. if I want to wrap it with a a GUI or similar?

  3. Hi Marcos, i think it's quite easy to invoke the twiddle shell directly from your GUI application, since twiddle is a CLI.

  4. Amid the security check in the airplane terminal essentially the watch checking should be sufficient. As people can never be 100% reliable, in addition they can never be that much productive like the electronic security gadgets.Best Security Place reviews

  5. Alongside the clock radio itself that contained the camera and transmitter, they were likewise given a beneficiary, A/V links and a connector to control the four-channel collector. Witty Spy

  6. CNN announced about a woman from Florida that needed to drive to an alternate city for work every day.

  7. Great Post,really it was very helpful for us.
    Thanks a lot for sharing!
    I found this blog to be very useful!!
    JAVA training in Bangalore