Tuesday, February 16, 2010

JBoss Twiddle

Today i was wondering Where exactly Twiddle plays its role ? one can do a lot using GUI but sometimes it would be simplest to use a command line. Thats where twiddle comes into picture.

To query any application server(jvm information) we can follow any of this approach Generic JMX, WebLogic T3, JBoss RMI, Tomcat RMI, WebSphere SOAP .

You can connect to Jboss either using RMI or generic JMX method .

JBoss provides a very simple command-line application, called twiddle,that lets you query MBeans, get and set attribute values, and even invoke operations. If you need to automate access to JBoss, twiddle is the easiest and best tool to use.

The twiddle script sits in the bin directory, next to the startup and shut-down scripts. You can run it from any terminal window, and it’s very easy to use. By default, twiddle connects to localhost:1099 port. If your using any other port its recommended to use -s localhost:differentport

The GET command lets you query an MBean by name. Pass in the name of the MBean and a list of attributes to retrieve:

[bin]$ ./twiddle.sh get jboss.system:type=ServerInfo FreeMemory ActiveThreadCount

If you don’t specify any attributes, you’ll get all of them:
[bin]$ ./twiddle.sh get jboss.system:type=ServerInfo
JavaVendor=Apple Computer, Inc.
JavaVMName=Java HotSpot(TM) Client V
JavaVMVendor="Apple Computer, Inc."
OSName=Mac OS X

The set command sets an attribute value on an MBean. This command sets the connection pool size for DefaultDS to 25:

[bin]$ ./twiddle.sh set jboss.jca:name=DefaultDS,service=ManagedConnectionPool \
MaxSize 25

You can invoke MBean operations using the invoke command. The out-put will be the return value, if any, of the method. This command asks for garbage collection to be run:

[bin]$ ./twiddle.sh invoke jboss.system:type=Server runGarbageCollector
If you check the console log, you will see the results of running garbage
18:28:57,779 INFO [Server] Total/free memory: 132775936/91869984
18:28:59,429 INFO [Server] Hinted to the JVM to run garbage collection
18:28:59,431 INFO [Server] Total/free memory: 132775936/9236628

If you are on a remote machine, add the -s option to specify the host you are trying to talk to:
You can run that command from any remote machine to shut down your JBoss instance

[bin]$ ./twiddle.sh -s hostname invoke jboss.system:type=Server shutdown

Below are few examples connected to remote server with authentication enabled

To list all mbeans
./twiddle.sh -s jnp://IPAddress:1099 -u admin -p xxxx serverinfo –l or
./twiddle.sh -s IPAddress -u admin -p xxxx serverinfo –l

$ ./twiddle.sh -H serverinfo
Get information about the MBean server

usage: serverinfo [options]

-d, --domain Get the default domain
-c, --count Get the MBean count
-l, --list List the MBeans
-- Stop processing options

$ ./twiddle.sh --server=IPAddress:1099 serverinfo --count

$ ./twiddle.sh --server=IPAddress:1099 serverinfo --domain

We can query only required mbeans using 'jboss.jca:*'

./twiddle.sh -s IPAddress -u jbadmin -p XXXX query 'jboss.jca:*'

To query the MBeanInfo for an MBean, use the info command

./twiddle.sh -s IPAddress -u admin -p XXXX info 'jboss.jca:service=ManagedConnectionPool,name=com.client.class.XYZDataSource'

Description: Management Bean.
+++ Attributes:
Name: BlockingTimeoutMillis
Type: int
Access: rw
Name: BackGroundValidationMinutes
Type: long
Access: rw
Name: PreFill
Type: boolean
Access: rw
Name: State
Type: int
Access: r-
Name: AvailableConnectionCount
Type: long
Access: r-
Name: BackGroundValidation
Type: boolean
Access: rw
Name: ManagedConnectionFactoryName
Type: javax.management.ObjectName
Access: rw
Name: UseFastFail
Type: boolean
Access: rw
Name: ConnectionCount

Use the get command to see current values of the attributes (in example we are trying for AvailableConnectionCount

./twiddle.sh -s IPAddress -u admin -p XXXX get jboss.jca:service=ManagedConnectionPool,name=com.client.class.XYZDataSource AvailableConnectionCount


Summary of Twiddle information you may require

# JVM Heap Usage
twiddle get "jboss.system:type=ServerInfo" FreeMemory
twiddle get "jboss.system:type=ServerInfo" TotalMemory
twiddle get "jboss.system:type=ServerInfo" MaxMemory

#AP Server Thread Usage & Configuration
twiddle get "jboss.system:type=ServerInfo" ActiveThreadGroupCount
twiddle get "jboss.system:type=ServerInfo" ActiveThreadCount
twiddle get "jboss.jca:service=WorkManagerThreadPool" QueueSize
twiddle get "jboss.jca:service=WorkManagerThreadPool" MaximumQueueSize
twiddle get "jboss.jca:service=WorkManagerThreadPool" MinimumPoolSize
twiddle get "jboss.jca:service=WorkManagerThreadPool" MaximumPoolSize

#Connection Pool Utilization
twiddle get "jboss.jca:name=HPS,service=ManagedConnectionPool" ConnectionCount
twiddle get "jboss.jca:name=HPS,service=ManagedConnectionPool" AvailableConnectionCount
twiddle get "jboss.jca:name=HPS,service=ManagedConnectionPool" MinSize
twiddle get "jboss.jca:name=HPS,service=ManagedConnectionPool" MaxSize
twiddle get "jboss.jca:name=HPS,service=ManagedConnectionPool" InUseConnectionCount

#Get Server Thread Dump
twiddle invoke "jboss.system:type=ServerInfo" listThreadDump

# Force GC
twiddle invoke "jboss.system:type=Server" runGarbageCollector
11:27:14,208 INFO [Server] Total/free memory: 133365760/94608856
11:27:14,676 INFO [Server] Hinted to the JVM to run garbage collection
11:27:14,676 INFO [Server] Total/free memory: 133365760/95472528

For now this was a bit knowledge I shared about twiddling. Hope to extend and share my knowledge more and soon in the nearby future.


  1. JBoss 5.1: The shutdown example doesn't work. Others do, but it appears something is stopping twiddle.sh making shutdown/GC/reset calls on the Server object. The command runs, it returns 'null'. And the GC example doesn't print anything to the logs.

    Any thoughts?

  2. Are you trying with following command to shutdown the remote host right and remote port running on 1099(JNDI) ?

    ./twiddle.sh -s remotehostname:JNDI invoke jboss.system:type=Server shutdown