Connecting to a Tomcat instance with JConsole

First of all, where to find JConsole: it's part of Sun's JDK. Both the Windows and the Linux versions of Sun's JDK (not JRE!) contain JConsole, so it's quite trivial to get. Second: enable JMX remote connections in your Tomcat. If you're running Tomcat on a Debian or Ubuntu server, then you've to add the required startup parameters to the /etc/default/tomcat5.5 file to the CATALINA_OPTS variable. Eg.
CATALINA_OPTS="-Djava.awt.headless=true -Xmx128M -server -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
(Note: the -Djava.awt.headless=true -Xmx128M -server parameters are there by default).

Now start JConsole (if you're using an Ubuntu desktop and installed the sun-java5-jdk package, then you'll find a "Sun Java 5.0 Console" item in your Applications / System Tools menu), select the Remote tab, enter hostname and port number (7091 in the above example) and connect. You might still get connection error though.

If you're using JDK6 on your desktop, then try running JConsole from the command line using the -debug option. It'll display the exceptions that JConsole throws. Eg. I got something like this:
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused: connect

As it turned out, the hosts file on the Tomcat server was "corrupt". It contained something like this:
127.0.0.1       localhost
127.0.1.1       myserver.example.com myserver
(...)

There was no network interface set up with the IP 127.0.1.1 and JConsole tried to connect to this IP since Tomcat's JVM told it to. (Note: even if there was an interface with that IP, it'd have been no good since it's an internal/loopback IP address and my desktop PC could not have connected to it anyway.) Fixing the hosts file (by changing the 127.0.1.1 to the correct 192.168.0.108 IP) fixed the JConsole connection problem too.

However your problem might lie elsewhere. If you're using JDK5, then the -debug option is not available with that version of JConsole. You've to use Java logging as described here or here. It involves creation of a special logging.properties file and starting JConsole with the -J-Djava.util.logging.config.file=logging.properties option.

P.S.: unfortunately JConsole is unusably slow for me, but this might be a problem with LTSP (since my client is an LTSP "thin" client - it's actually a normal PC, but the X11 over SSH solution used in LTSP already caused me some headache with other programs, so it might be the culprit here as well).

P.S.2: setting up JMX in Tomcat with the -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false options is totally insecure! So if your Tomcat server is public and it's JMX port is unprotected, then don't use it like I did in my example.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

excellent

Thanks! Your hosts file comments solved my issue.

jConsole and "Locking assertion failure"

Whenever I start jConsole in Ubuntu (8.10), the first line I see in the terminal is:
Locking assertion failure.  Backtrace:

And as I already said: jConsole is painfully slow in everything (whatever I click, jConsole takes ages to react).

I've now downloaded the latest available JDK (1.6 Update 12) and tried jConsole with that. The locking assertion failure is gone (and jConsole got a new, fancy skin), but it's still painfully slow. Sad It's usable to some degree (I sense a small amount of speedup) ... I can load one screen and it'll update from time to time. I just cannot switch from one screen to another ... at least not in reasonable time.

However the JRockit Mission Control works without a hitch. Unfotunately you cannot change one for the other: the latter works only with the JRockit JVM (so you cannot debug Sun JVM issues with it) and the former is nothing compared to Mission Control so you won't even think about using JConsole with a JRockit JVM.

Not able to run JConsole

Hi ,

Im not able to run JConsole in Ubuntu 8.04, Im using Java1.6.0_07.I have .sh file in which i have the JMX commands.Below is the content of my .sh file

#!/bin/sh
java -Dsun.lang.ClassLoader.allowArraySyntax=true
-Dconfig.file=pop.properties
-Dconnection.file=Connection.properties
-Dcom.sun.management.enableThreadContentionMonitoring=true
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false-server -jar Hello.jar

to run i typed $chmod +x run.sh
$./run.sh

its showing the following error:
14 may. 2009 13:46:48 sun.rmi.transport.tcp.TCPTransport$AcceptLoop executeAcceptLoop
ATTENTION: RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=35437] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:89)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:387)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:359)
at java.lang.Thread.run(Thread.java:636)
14 may. 2008 13:46:48 sun.rmi.transport.tcp.TCPTransport$AcceptLoop executeAcceptLoop

the same file(run.bat) is working well in windows. Do i have to do any configuration for JConsole in Ubuntu?

Re: Not able to run JConsole

First of all: I do not see a jConsole execution in your example. You wrote that you executed your run.sh script and it produced the given error message (stacktrace). But your run.sh script does not invoke jConsole at all, so why did you give the title "Not able to run JConsole" for your post? Shock I assume your script started your app and you invoked jConsole with another command and that's the one that resulted in the given error message.
Second: in your run.sh script the invocation of the JRE is split over multiple lines, but there's no "\" to escape the end of line.
Third: on the last line you've this: "-Dcom.sun.management.jmxremote.ssl=false-server -jar Hello.jar". The "-server" parameter should be separated with a space from the "-Dcom.sun.management.jmxremote.ssl=false" parameter.
Fourth: you're still missing one JRE parameter from your script. You need a "-Dcom.sun.management.jmxremote" too.
So your script should look something like this:
#!/bin/sh
java -Dsun.lang.ClassLoader.allowArraySyntax=true\
-Dconfig.file=pop.properties\
-Dconnection.file=Connection.properties\
-Dcom.sun.management.enableThreadContentionMonitoring=true\
-Dcom.sun.management.jmxremote\
-Dcom.sun.management.jmxremote.port=12345\
-Dcom.sun.management.jmxremote.authenticate=false\
-Dcom.sun.management.jmxremote.ssl=false\
-server\
-jar Hello.jar

And note that the "-server" parameter is only recognized by the JDK version of the JRE. In case of Ubuntu, the "java" executable installed through the sun-java6-bin package does support the "-server" switch. But if you install on Windows, then you need a JDK (not just a JRE) to be able to use the "-server" switch.

It all became more clear to

It all became more clear to me after I've read this post.
I wanna thank the author of one of the previous comments: I was facing some problems with launching it on my Ubuntu 8.04, but after I've read the reply, I added missing "-Dcom.sun.management.jmxremote" for JRE, and bingo - it moved from the dead point.

Best Regards,
Mike

Thanks!

Since Oracle took over Sun, I can't seem to find documentation as easily as I used to. Found your blogpost instead, and it instantly solved my problem. Thanks! keep up the good work!

Thanks and 127.0.0.1 IP address issue

I tried many other posts and even the Tomcat6 documentation to enable remote JMX and didn't work, but this is what worked .. thank you so much for sharing the information.
Just to comment on the /etc/hosts file issue. It is not really corrupt, it looks like Ubuntu does that by default for some reason and I have to go every time to correct the IP for the machine where the OS is installed.
This post might explain the problem, http://serverfault.com/questions/363095/what-does-127-0-1-1-represent-in-etc-hosts

Hope this will help.. thanks again!
Nadia

Re: Thanks and 127.0.0.1 IP address issue

Thanks for the feedback on the 127.0.1.1 problem. I didn't know about the reason behind it.

Syndicate content