20 September 2007

Command Line Monitoring of Thread Pool Sizes

Want to periodically view the OC4J thread pool sizes from the command line?

Using Groovy + JMX , its dead simple:
import demo.oc4j.jmx.*;
import java.text.*;

def period = 5000L
def client = new OC4JClient()
def df = DateFormat.getTimeInstance(DateFormat.LONG)

try {
client.connect("service:jmx:rmi://10.187.112.178:23791",
"oc4jadmin", "welcome1")

println "$client\n"

http = client.helper.createGroovyMBean(
"oc4j:j2eeType=ThreadPool,name=http,J2EEServer=standalone")

system = client.helper.createGroovyMBean(
"oc4j:j2eeType=ThreadPool,name=system,J2EEServer=standalone")
jca=client.helper.createGroovyMBean(
"oc4j:j2eeType=ThreadPool,name=jca,J2EEServer=standalone")


while(true) {
now = df.format(new Date(System.currentTimeMillis()));
println "$now HTTP:[$http.poolSize] JCA:[$jca.poolSize] System:[$system.poolSize]"
Thread.sleep(period)
}
} finally {
println 'Closing'
client.close()
}

This makes use of the OC4J helper library, which you can access here.

A simple script to run this would look like this:

@setlocal
set J2EE_HOME=d:\java\oc4j-10133-prod\j2ee\home
set GROOVY_HOME=d:\java\groovy-1.0
set classpath=lib\oc4jgroovy.jar;%GROOVY_HOME%\lib\commons-cli-1.0.jar;/
%GROOVY_HOME%\embeddable\groovy-all-1.0.jar;%J2EE_HOME%\admin_client.jar;%J2EE_HOME%\oc4jclient.jar

java -classpath %CLASSPATH% groovy.lang.GroovyShell src\threadlevel.groovy
@endlocal


When the script is run, it produces this sort of output:

Client is connected to: rmi://10.187.112.178:23791 oc4jadmin [connectionCaching:
true, httpTunneling:false, locale:not set]

1:03:54 HTTP:[7] JCA:[1] System:[7]
1:03:59 HTTP:[7] JCA:[1] System:[7]
1:04:06 HTTP:[7] JCA:[1] System:[7]
1:04:11 HTTP:[7] JCA:[1] System:[7]


----------------
Listening to: Ned's Atomic Dustbin - What Gives My Son?

7 comments:

Anonymous said...

Hello Steve,

where i can found the libary: oc4jgroovy.jar ?




Best Regards,
Ralf (T-Systems)

Ralf.Steffens@t-systems.con

Buttso said...

Hi Ralf -- I'm sending it to you over email.

cheers
-steve-

Buttso said...

Hi Ralf -- I'm sending it to you via email.

cheers
-steve-

aeh said...

Could I also get a copy? :)

aeh said...

Can I also get a copy? :)

Buttso said...

If you get me your email address and I'd be happy to send it on.

-steve-

NV - Nimeshkumar Vadgama said...

Hi Buttso,

Interesting article, indeed !!

I would be glad if you could send me oc4jgroovy.jar to my email nimesh.qa@gmail.com

With Regards,
NV