The Web Console gives you access to all the services in JBoss, but it does have one huge limitation. It is a web application that requires that an interactive user do the pointing and clicking. That's fine most of the time, but sometimes you'll want to automate access to the server. 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. How do I do that?The twiddle script sits in the bin directory, next to the startup and shutdown scripts. You can run it from any terminal window, and it's easy to use. 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 FreeMemory=90167064 ActiveThreadCount=46 If you don't specify any attributes, you'll get all of them: [bin]$ ./twiddle.sh get jboss.system:type=ServerInfo HostAddress=192.168.0.101 AvailableProcessors=1 OSArch=ppc OSVersion=10.3.9 HostName=toki.local JavaVendor=Apple Computer, Inc. JavaVMName=Java HotSpot(TM) Client VM FreeMemory=90898472 ActiveThreadGroupCount=6 TotalMemory=132775936 JavaVMVersion=1.4.2-38 ActiveThreadCount=45 JavaVMVendor="Apple Computer, Inc." OSName=Mac OS X JavaVersion=1.4.2_05 MaxMemory=218103808 If you need to use a value in a script, use the --noprefix flag: [bin]$ ./twiddle.sh get --noprefix jboss.system:type=ServerInfo FreeMemory 92063536 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 MaxSize=25 You can invoke MBean operations using the invoke command. The output 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 collection: 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/92366288 The following example invokes the clearAlert method on the free memory monitor: [bin]$ ./twiddle.sh invoke jboss.monitor:service=FreeMemoryMonitor\ clearAlert If you are on a remote machine, add the -s option to specify the host you are trying to talk to: [bin]$ ./twiddle.sh -s hostname invoke jboss.system:type=Server shutdown You can run that command from any remote machine to shut down your JBoss instance. What just happened?You accessed the MBeans on your JBoss instance from a remote machine using the twiddle command-line script. twiddle gives you fast, scriptable access to any JBoss instance. |