extended twiddle: queryMethod and listDomains

Torben | jboss | Monday, April 6th, 2009

The last few days I missed some functionality in twiddle.

For those not familiar with twiddle:
twiddle is a command-line tool that acts as a JMX client to a (remote) jboss server.
It is distributed with JBoss AS itself and is located in $JBOSS_HOME/bin.

twiddle is capable of that:

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh –help-commands
twiddle.sh commands:
jsr77 Print out JSR77 related information
xmbean Print out mbean metadata as an xmbean descriptor
info Get the metadata for an MBean
get Get the values of one or more MBean attributes
invoke Invoke an operation on an MBean
create Create an MBean
setattrs Set the values of one or more MBean attributes
unregister Unregister one or more MBeans
query Query the server for a list of matching MBeans
set Set the value of one MBean attribute
serverinfo Get information about the MBean server
torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

Especially invoke is a great thing!

Here`s an example: "Print out JNDI"

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh invoke jboss:service=JNDIView list true
<h1> Other components with java:comp namespace</h1>
<h1>java: Namespace</h1>
<pre>
+- securityManagement (class: org.jboss.security.integration.JNDIBasedSecurityManagement)
+- comp (class: javax.namingMain.Context)
+- XAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
+- TransactionPropagationContextImporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
+- policyRegistration (class: org.jboss.security.plugins.JBossPolicyRegistration)
+- ClusteredConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- Mail (class: javax.mail.Session)
+- TransactionPropagationContextExporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
+- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+- jaas (class: javax.naming.Context)
| +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

But …. for invoking a MBean method you have to remember the following things:

  1. the domain, the MBean can be found in
  2. the key properties of the MBean
  3. the method name to invoke
  4. and last but not least the parameters of the method (if there are any).

Back to the first sentence … I wanted to be able to google a method regardless of its location and implemented another twiddle command called queryMethod.

queryMethod

This command

  • queries the methods of MBeans (case-insensitive)
  • can be filtered by domains
  • gives you all information needed to invoke that method
  • can just show the hit count

The command specific help of a twiddle command is shown with the -H option:

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh -H queryMethod
Help for command: ‘queryMethod’

Query the server for a list of matching methods of MBeans

usage: queryMethod [options] <query>
options:
-c, –count Display the matching method count
-f, –filter Filter by domain
— Stop processing options
Examples:
query methods of all MBeans: queryMethod list
query all methods of all MBeans in the jboss domain: queryMethod -f "jboss:*" list
torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

Let`s do an example to make that clearer:

"List all MBean methods with `list` in the method name"

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh queryMethod list
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listLoadedClasses
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listImports
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" clearBlackList java.lang.String
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listLoadedResourceNames
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listResourceCache
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listLoadedResources
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listPolicyDetails
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listExportedPackages
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" listResourceBlackList
jboss.classloader:id="bootstrap-classloader:0.0.0$MODULE" clearBlackList
jboss.deployment:id="WebServer",type=Component listAttachments boolean
jboss.classloader:id="vfsfile:/Users/torben/Dev/jit-consulting/jboss-5.0.1.GA/server/default/deploy/messaging/messaging-service.xml" listLoadedClasses
jboss.classloader:id="vfsfile:/Users/torben/Dev/jit-consulting/jboss-5.0.1.GA/server/default/deploy/messaging/messaging-service.xml" listImports

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

This gives you a huge list of matching methods:

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh queryMethod -c list
1272
torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

So sometimes it`s better to limit the result list.

Let`s do the last example again, but limit the search to the jboss domain by setting a filter:

"List all MBean methods in the jboss domain with `list` in the method name"

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh queryMethod -f "jboss:*" list
jboss:type=Service,name=SystemProperties removeListener org.jboss.util.property.PropertyListener
jboss:type=Service,name=SystemProperties addListeners [Lorg.jboss.util.property.PropertyListener;
jboss:type=Service,name=SystemProperties addListener org.jboss.util.property.PropertyListener
jboss:type=Service,name=SystemProperties addListener java.lang.String
jboss:service=JNDIView list boolean
jboss:service=JNDIView listXML
jboss:service=AttributePersistenceService apmListAll
jboss:service=AttributePersistenceService apmListAllAsString
jboss:service=invoker,type=unified addListener org.jboss.remoting.callback.InvokerCallbackHandler
jboss:service=invoker,type=unified removeListener org.jboss.remoting.callback.InvokerCallbackHandler

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

This is somewhat more handy when dealing with general query strings. The queryMethod output can be copied&pasted along with the invoke command with setting the appropriate parameters.

But ... the next question came up: what can I limit the query to? This lead me to the second, very simple command: listDomains

listDomains

This command just lists the available domains of the jboss server; and is countable too.
The command specific help:

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh -H listDomains
Help for command: 'listDomains'
Query the server for a list of available domains
usage: listDomains [options]
options:
-c, –count Display the domain count
— Stop processing options
torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

listDomains in action:

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh listDomains
jboss.deployment
jboss.web
jboss.ws
jboss.messaging.destination
jboss.rmi
jboss.messaging.connectionfactory
jboss.security
jboss.jdbc
jboss.mq
jboss.remoting
jboss.jca
jboss.classloader
com.arjuna.ats.properties
jboss.admin
jboss.j2ee
jboss
jboss.aop
jboss.jmx
jboss.messaging
jboss.web.deployment
jboss.pojo
jboss.cache
JMImplementation
jboss.jacc
jboss.ejb
jboss.system
jboss.vfs
jboss.alerts
jboss.management.local
torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh listDomains -c
29
torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

Installation

Hopefully the two commands get committed to the jboss repository so that no further patching is needed. If not, follow these instructions:

Binary installation

Download twiddle.jar and substitute $JBOSS_HOME/bin/twiddle.jar

Note:
If someone is interested in building twiddle by him/herself, the source code patch can be obtained here. Just apply it to jbossas-trunk/console

Verify installation

Check with

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >% ./twiddle.sh –help-commands
twiddle.sh commands:

queryMethod Query the server for a list of matching methods of MBeans
listDomains Query the server for a list of available domains

torben@jit:~/Dev/jit-consulting/jboss-5.0.1.GA/bin/ >%

if the additional commands show up.

Powered by Qumana

1 Comment »

  1. It will be part of JBoss 5.1.0.GA, thanks!

    https://jira.jboss.org/jira/browse/JBAS-6849

    Comment by Dimitris Andreadis — May 4, 2009 @ 9:33

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress | Theme by Roy Tanck