天天看点

A simple usecase of jconsole

[b]1: What is jconsole?[/b]

The jconsole command launches a graphical console tool that enables you to monitor and manage Java applications and virtual machines on a local or remote machine.

[b]2: What it can do?[/b]

The jconsole can:

1) Viewing summary information

2) Monitoring Memory Consumption

3) Monitoring Thread Use

4) Monitoring Class Loading

5) Monitoring and Managing MBeans

6) Viewing VM Information

[b]3: How to use it?[/b]

refer to 4: demo

[b]4: Jconsole config files location[/b]

You can set the ssl/remote port/access right in below jconsole config folder,

[color=green]%JAVA_HOME%\jre\lib\management\[/color]

After you setup the config in the management.properties file you can specified the config file location in the java application start parameter,such as:

[color=green]-Dcom.sun.management.config.file=%java_home%\jre\lib\management\management.properties -jar C:\oc4j_101330_seed\j2ee\home\oc4j.jar[/color]

[b]5: Demo[/b]

Here use Java2DDemo again to demonstrate the usage:

a) start the Java2DDemo with [color=green]-Dcom.sun.management.jmxremote[/color] options

[color=green]C:\>java -Dcom.sun.management.jmxremote -jar "C:\Program Files\Java\jdk1.5.0_06\demo\jfc\Java2D\Java2Demo.jar[/color]

b) use jps to find the PID of the Java2DDemo java application, you can find the PID by window task manager.

[color=green]C:\>jps

1440 Program

492 Jps[/color]

c) start jconsole

[color=green]C:\>jconsole 1440[/color]

Now the jconsole UI displayed.

[img]http://dl.iteye.com/upload/attachment/254204/a9ef5a58-8652-330c-816e-974b4d08011f.gif[/img]

d) Test for monitor the local application server

Here choose the OC4J to do the test.

For WindowsXP platform, pls change your TMP path to another place, here i changed it to c:\TEMP

Start the oc4j with [color=green]-Dcom.sun.management.jmxremote[/color] option. it's better to start it separately, will get error when start it in eclipse servers console.

the error messgae is:

Exception in thread "main" java.lang.Exception: Could not open

PerfMemory

find the PID of it.

[color=green]C:\>jps

5332 oc4j.jar

2032 Jps[/color]

e) Start remote monitor

without authentications because just used for test env

[color=green]com.sun.management.jmxremote.port=9999

com.sun.management.jmxremote.ssl=false

com.sun.management.jmxremote.authenticate=false[/color]

--> Start jconsole --> set the right hostname/port/username/password (if any) to connect.

[b]6: Problems[/b]

a) When use jconsole meet: [color=red]Exception in thread "main" java.lang.Exception: Could not open PerfMemory[/color]

the solution is:

[color=green]set the tmp variable to c:\tmp for the process calling the application as well as the process calling the monitoring tool.[/color]

quote from [url]http://forums.sun.com/thread.jspa?threadID=730397[/url]

[color=gray]This is usually due to a permissions problem. There's two known causes.

The first happens when the tools (jstat and jps) are run by a different

user id than the application. The second, which is probably more likely

here, is cause by a bug the JVM when it encounters inherited DACLS in

the default temporary directory. inherited DACLS are usually set up by

the IT organization on users home directories, though they can also

occur on other system directories. We do not yet have a fix for this bug

but there is a work around.

The workaround is to set the TMP environment variable (either globally

or for all processes started by a specific user or for just the target

process and the tools) to point to a directory that doesn't get

inherited DACLS. Usually something like c:\tmp will work. Trying setting

TMP=c:\tmp (after making the directory, of course) for both the

application(s) you want to monitor and the command window where you run

the jstat and jps tools and see if that fixes the problem. If it doesn't

fix the problem, I'll need to see the output of the following commands

(using the original TMP setting and then again with TMP=c:\tmp)

cacls %TMP%

cacls %TMP%\hsperfdata_*

Another workaround is to point TMP to a FAT32 file system and then set

-XX:+PerfBypassFileSystemCheck on the target applications' command lines

and -J-XX:+PerfBypassFileSystemCheck on the jstat and jps command lines.

This works because FAT32 doesn't support DACLS, so the JVM doesn't

attempt to create them; however, the the PerfBypassFileSystemCheck is

needed because the JVM won't enable the monitoring capaibilties when TMP

is set to device that doesn't support DACLs.

There's more information about setting TMP globally and on a per-user

basis in the jvmstat faq:

http://java.sun.com/performance/jvmstat/faq.html

See item #4.

Brian[/color]

b) meet below error when use jconsole:

[color=red]Unable to attach to 4800: Could not map vmid to user name[/color]

the cause can be found in [url]http://java.sun.com/performance/jvmstat/faq.html#15[/url]

but i could not understand and don't know how to use the workaround it provides. My solution here is to start the OC4J separately instead of start it in eclipse servers. It works.

[b]7: Reference[/b]

[1][url]http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html[/url]

[2][url]http://java.sun.com/j2se/1.5.0/docs/guide/management/faq.html[/url]

[3][url]http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html[/url]

[4]

上一篇: 什么是WBS?
下一篇: div遮罩效果