Twiddle Archive

JBoss Twiddle utility examples

The below post describes some common usage scenarios of the twiddle JBoss command line utility.

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.

Twiddle utility is located in $JBOSS_HOME/bin directory.

You can refer a good read on Twiddle basics from the below link.

http://weblogic-wonders.com/weblogic/2010/12/22/jboss-command-line-utility-twiddle/

Twiddle commands to read the information.

Getting Server Information:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss.system:type=ServerInfo"

Getting Global JNDI Information:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss:service=JNDIView"

Getitng Jboss Logging Information

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss.system:type=Log4jService,service=Logging"

Getting Thread Pool information:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss.system:service=ThreadPool"

Twiddle commands to execute operations.

Deploying an application:

twiddle.bat -s jnp://localhost:1099  --user=admin --password=admin invoke "jboss.system:service=MainDeployer" deploy "file:\D:\TestApp.war"

Re-Deploying an application:

twiddle.bat -s jnp://localhost:1099  --user=admin --password=admin invoke "jboss.system:service=MainDeployer" redeploy "file:\D:\TestApp.war"

Un-Deploying an application:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss.system:service=MainDeployer" undeploy "file:\D:\TestApp.war"

Capturing Thread Dumps:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=ServerInfo" listThreadDump

List the thread CPU utilization

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=ServerInfo" listThreadCpuUtilization
NOTE: The output is in table format, you can redirect the output in a html page for better viewing.
G:\jboss-eap-5.1\jboss-as\bin>twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=ServerInfo" listThreadCpuUtilization>> c:\out.html

Listing the memory pools:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss.system:type=ServerInfo" listMemoryPools true

Changing logging levels to Debug

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=Log4jService,service=Logging" setLoggerLevel org.apache debug

Stopping a  DataSource:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss:service=Hypersonic,database=localDB"  stop

Starting a DataSource:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss:service=Hypersonic,database=localDB"  start

Stopping the server:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss.system:type=Server" shutdown

Some of the other JMX services that can be used as below.

•             jboss:type=Service,name=SystemProperties     -   enables you to view the system properties

•             jboss:service=JNDIView -                                                 enables you to view the contents of JNDI

•             jboss.system:type=Log4jService,service=Logging -  enable you to change log levels

•             jboss.system:service=ThreadPool -                             enables you to change the thread pool

•             jboss.system:type=Server -                                            provides information about the server

•             jboss.system:type=ServerConfig -                            provides information about the server

•             jboss.system:type=ServerInfo -                                provides information about the server

References:

http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.2/html/Server_Configuration_Guide/Connecting_to_the_JMX_Server-Command_Line_Access_to_JMX.html

Cheers,

Wonders Team 🙂

Thread Dumps in JBoss

The below article shows about capturing the Thread Dumps for JBoss Application Server in event of any server hangs or to diagnose any  performance bottlenecks using the JBoss Server Utilities.

Using JMX Console:

JMX-Console application is deployed on to the JBoss Application Server by default  and you can access the same using the below URL.

http://<HOST>:<PORT>/jmx-console/

NOTE: If the jmx-console prompts for the user credentials, use the default username/ password pair i.e. admin / admin.

1. Login into the JMX-Console.

Navigate to the  jboss.system object from the left panel –> Click on the ServerInfo MBean from the right panel.

Alternative to this navigation, you can directly go to the required MBean by typing in jboss.system:* in the filter criteria of the JMX console.

3. This would show all the server details like memory, chip architecture , ActiveThreadCount , HostAddress etc.

Navigate to the bottom of the page and click on the listThreadDump operation –>  Invoke.

4.  This would generate the thread dumps for analysis as shown below.

Using Twiddle:

1. Open command prompt.

2. Navigate to the $JBOSS_HOME/bin  directory.

NOTE: Make sure the JAVA_HOME is already set.

3. Execute the below command.

twiddle.bat –server jnp://<Host>:<Port> invoke  “jboss.system:type=ServerInfo”     listThreadDump

For ex:

twiddle.bat –server jnp://localhost:1299 invoke  “jboss.system:type=ServerInfo”     listThreadDump

Refer the below post for further understanding o f JBoss Twiddle Utility.

http://weblogic-wonders.com/weblogic/2010/12/22/jboss-command-line-utility-twiddle/

References:

http://community.jboss.org/wiki/Twiddle

Cheers,

Wonders Team. 🙂

JBoss Command Line Utility Twiddle

Recently I had faced a situation where I was forced to invoke a method on a particular “MBean” 10-15 times. I had completed this task manually from “JMX-Console”, but I didn’t feel it was elegant way of executing the task.

So I had started doing research to find out if there is better way of doing this task. Finally I found a utility called as “twiddle” which basically comes with every JBoss installation. In this article, I am just sharing information about what I had learned. There are many more complex tasks which can be performed with this utility.


Variables
:-

JBOSS_HOME :- This is the location where JBoss is installed.

Prerequisites :-

We need to set “JAVA_HOME” variable before executing twiddle. This can be done in two ways.
Solution 1:-

In the Profile :- In “bash profile”(I use ‘bash’ profile, same can be done with other profiles), so go to “HOME” directory( enter “cd” at command prompt), open “.bash_profile(make sure there is “dot” before “bash_profile”, this is secret file) and enter below lines.

JAVA_HOME=<location where “java” is installed>
export JAVA_HOME

Save the file and enter “source .bash_profile”. “source” command reads commands from the file and executes in current shell environment.

Solution 2 :-

Update “twiddle.sh”(Take backup before editing the file).
Add below lines

JAVA_HOME=<location where “java” is installed>
export JAVA_HOME
echo “VAS JAVA_HOME : ${JAVA_HOME}”

Note :- Solution “2” is better than “1” because solution 1 might effect other applications too, but solution “2” will effect only “twiddle.sh”

Validation :-

Enter “echo ${JAVA_HOME}” , this should return the location where the JBoss is installed. If this variable returns “empty” value, then this variable is not set properly, please check above steps.


Execution
:-

Go to the directory “JBOSS_HOME/bin” and execute “./twiddle.sh”. It should display the help options.

Help :-

./twiddle.sh –help-commands :- displays all the commands we can invoke on this utility.
./twiddle.sh –H<command> :- will provide additional information on particular command, such as syntax of the commands, options that can be passed to the command.

Example :-
./twiddle.sh -Hinvoke

Syntax :-

./twiddle.sh -s <serverUrl> -u <userName> -p <password> <command> [ command_arguments

serverUrl :- <protocol>://<serverName>:<port>
protocol :- jnp ( This is optional)
serverName :- Since we will be executing the command from the box where JBoss is installed, we can either give “localhost” or actual server name.
port :- 1099.  This the port where Jboss Naming service is listening. If you are using out of box Jboss installation then this will be the port. But if you changed this and you don’t remember the port, then either check the file “JBOSS_HOME/server/<serverName>/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml” or log on to “http://<serverName>:<port>/jmx-console” and click on “jboss” on left column and then click “service=Naming” and the value for the attribute “port”.

Commands :-

jsr77 :- displays jsr77 related information.
xmbean :- print out mbean metadata as an “xmbean” descriptor. In this file you can find all attributes and operations on a particular mbean.
info :- get the metdata for an MBean.
get :-  get value for an mbean attribute.
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
queryMethod :- query list of matchin methods on MBeans
listDomains :-  list all the domains.
query :-  query list of matching MBeans
set :- set the value for one MBean attribute
serverinfo :- get the information about MBean Server.


Examples :-

jsr77 :-

Displays the “jsr77” information for this particular server.

./twiddle.sh -s jnp://localhost:1099 -u admin -p admin jsr77

xmbean :-

Displays information of the MBean as “xmbean” descriptor.

./twiddle.sh -s jnp://localhost:1099 -u admin -p admin xmbean jboss:service=Naming

info :-

Query attribute of a particular bean.

./twiddle.sh -s jnp://localhost:1099 -u admin -p admin xmbean jboss:service=Naming

get :-

Get value of a particular ‘attribute’.

./twiddle.sh -s localhost:1099 -u admin -p admin get ‘jboss:service=Naming’ Name

Get value of a multiple ‘attributes’. The attributes must be separated by ‘Space’.

./twiddle.sh -s localhost:1099 -u admin -p admin get ‘jboss:service=Naming’ Name State

invoke :-

Invoke operation on a particular mbean.

./twiddle.sh -s localhost:1099 -u admin -p admin invoke jboss.system:type=ServerInfo listThreadCpuUtilization

Note :- There are multiple additional options, I didn’t explore them as of now.

create :-

Create an MBean.

I didn’t explore this command, I need to do research on this command a little more. I will update this article once I found more on this command.

setattrs :-

Set values of one or more bean attributes.

In below command we set values of two attributes “BackLog” and “JNPServerSocketFactoryBean” to “100” and “null” respectively.

./twiddle.sh -s localhost:1099 -u admin -p admin setattrs ‘jboss:service=Naming’ Backlog 100 JNPServerSocketFactory null

unregister :-

Unregister a one or more Mbeans.

Again I didn’t get much chance to explore this command, will update on this on this command once I am done with research.

queryMethod :-

Query all methods on all Mbeans.

./twiddle.sh -s localhost:1099 -u admin -p admin queryMethod list

Query methods on few mbeans

./twiddle.sh -s localhost:1099 -u admin -p admin queryMethod -f ‘jboss:*’ list

listDomains :-

List all the domains.

./twiddle.sh -s localhost:1099 -u admin -p admin listDomains

query :-

Display all Mbeans on the server.

./twiddle.sh -s localhost:1099 -u admin -p admin query ‘*:*’

Display MBeans on particular domain. In below command we display in the domain “jboss:j2ee”.

./twiddle.sh -s localhost:1099 -u admin -p admin query ‘jboss.j2ee:*’

set :-

Set the value on particular attribute.

./twiddle.sh -s localhost:1099 -u admin -p admin set ‘jboss.system:service=Logging,type=Log4jService’ RefreshPeriod 60

serverinfo :-

Display information about MBean server.

./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -l

Number of MBeans on the server.

./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -c

Default Domain.

./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -d

Few Important Useful Operations :- We can do many operations with “Twiddle”, below are just few examples.

Deploying an Application :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.service:MainDeployer’ deploy “file:///tmp/VASVijay/VASApp.war”

Undeploying an Application :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.service:MainDeployer’ undeploy “file:///tmp/VASVijay/VASApp.war”

Redeploying an Application :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.service:MainDeployer’ redeploy “file:///tmp/VASVijay/VASApp.war”

Take ThreadDump :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.system:type=ServerInfo’ listThreadDump
Get Server Info :-

./twiddle.sh -s localhost:1099 -u admin -p admin get ‘jboss.system:type=ServerInfo’

Issues :-

Twiddle will be throwing exception like below, this is a know nexception. This is because “twiddle” is executed on separate “JVM” from the “JBoss JVM”. There is patch for this at “https://issues.jboss.org/browse/JBAS-4323”

10:16:57,158 ERROR [Twiddle] Exec failed java.io.NotSerializableException: org.jboss.resource.connectionmanager.TxConnectionManager
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at java.util.ArrayList.writeObject(ArrayList.java:570)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)

Pending Tasks :-

Exploring below commands and options :-

Options :- “-c” option. I was not able to find out correct way to execute this option, so I am checking out with Redhat on this option. If any one of you know how to use this option, please let me know. Thanks in advance for sharing the solution.

Commands :- “create” and “unregister” commands,  I need to write code to explore these. I will soon add examples to execute these commands, once I test these commands successfully.

References :-

This article wouldn’t had been possible without ‘google’ and many wonderful articles written by experts. Few of them are below. I referenced many sites for this utility, I couldn’t remember all site names, If I didn’t mention any particular site name whose example I had used,  its just that I don’t remember the site name, I sincerely apologize for not mentioning the site name.  Please let know if any one feels I had missed to add any particular site in the reference, I will add the site to the references.

http://community.jboss.org/wiki/Twiddle

http://nagpals.com/jboss-examples-of-twiddle

I hope that you all liked this article, if there any issues or suggestions or if you don’t like anything in the article,  please comment.

For some more Twiddle examples, refer the below post.

http://weblogic-wonders.com/weblogic/2011/02/13/twiddle-utility-examples/

Thanks,

Wonders-Team,

Dream, Learn, Share and Inspire !