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:differentportThe 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 ActiveThreadCountFreeMemory=90167064ActiveThreadCount=46If you don’t specify any attributes, you’ll get all of them:[bin]$ ./twiddle.sh get jboss.system:type=ServerInfoHostAddress=192.168.0.101AvailableProcessors=1OSArch=ppcOSVersion=10.3.9HostName=toki.localJavaVendor=Apple Computer, Inc.JavaVMName=Java HotSpot(TM) Client VFreeMemory=90898472ActiveThreadGroupCount=6TotalMemory=132775936JavaVMVersion=1.4.2-38ActiveThreadCount=45JavaVMVendor="Apple Computer, Inc."OSName=Mac OS XJavaVersion=1.4.2_05MaxMemory=218103808The 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 25MaxSize=25You 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 runGarbageCollectorIf you check the console log, you will see the results of running garbagecollection:18:28:57,779 INFO [Server] Total/free memory: 132775936/9186998418:28:59,429 INFO [Server] Hinted to the JVM to run garbage collection18:28:59,431 INFO [Server] Total/free memory: 132775936/9236628If 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 shutdownBelow 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 serverinfoGet information about the MBean serverusage: serverinfo [options]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 --count460$ ./twiddle.sh --server=IPAddress:1099 serverinfo --domainjbossWe 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: ConnectionCountUse 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 AvailableConnectionCountoutputAvailableConnectionCount=50.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.