12

I am using jdk64 and my java version is 1.6.0_24. I am running both (Tomcat java process and VisualVM) processes as Administrator on Windows Server 2008.

Tomcat is running with -Xmx7196m, where as jvisualvm is running with -Xms24m and -Xmx256m. Could this be the cause?

Kuldeep Jain
  • 8,409
  • 8
  • 48
  • 73

3 Answers3

22

You need to add the JMX parameters to enable the JMX connection to your application, so add the following parameters:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8484
-Dcom.sun.management.jmxremote.ssl=false

Then You need to add your tomcat process manually, So right click on you localhost node -> Add JMX Connection -> type your port -> OK.

Your tomcat process will be listed in under localhost node.

Salah
  • 8,567
  • 3
  • 26
  • 43
  • Thanks, it worked. By default if I capture heap dump they go to `C:\Users\kuldeep\AppData\Local\Temp\visualvm.dat\localhost_PID` directory. Can I change this location? I don't have enough space in my `C:\` drive. – Kuldeep Jain Mar 10 '14 at 13:49
  • I used `jvisualvm.exe --userdir "E:\VisualVM_userdir"` to change `userdir`. That would enable capturing Snapshot to `userdir`. Would it also save head dump in there? – Kuldeep Jain Mar 10 '14 at 14:13
  • I closed and relaunched VisualVM and tomcat both. And now when I try to `Add JMX Connection` on same port it gives the error: **jmx connection service:jmx:rmi:///jndi/rmi://localhost:8484/jmxrmi already exists as localhost:8484**. But how do I open the existing one? – Kuldeep Jain Mar 10 '14 at 15:19
  • Look under your localhost node, you'll find the tomcat process, you don't have to add it each time. – Salah Mar 10 '14 at 15:21
  • 1
    No, it is not there for sure. Additionally I see `Computing description...` in the bottom right corner of VisualVM going on for quiet some time. – Kuldeep Jain Mar 11 '14 at 05:06
  • Restarting the m/c and re-launching the tomcat & jvisualvm solved the issue. – Kuldeep Jain Mar 11 '14 at 05:41
  • @KuldeepJain where did you add the parameters in the answer ? – mounaim Jan 26 '18 at 11:44
  • @mounaim You need to add those parameters as VM args while starting your application that you want to monitor `java -Dcom.sun.management.jmxremote.port=5000 -jar MyApplication.jar` You can refer to this link: https://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html – Kuldeep Jain Jan 27 '18 at 14:43
0

Our application server is JBOSS 6.1.0.final and our server itself is not starting on adding these lines to the run.conf.bat file -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8484 -Dcom.sun.management.jmxremote.ssl=false

0

The reason VisualVM cannot find Java because of OS process privileges.

If you start VisualVM with the same user & security context as Java app you will see it: VisualVM will gain access to sockets, /proc fs, etc...

To workaround the OS security stuff you can expose your Java app via JMX appending sys props:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=[...PORT...]
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost

java.rmi.server.hostname is an important security measure to prevent connection to your app JMX from outside. If you need a remote connection just pass the port with SSH tunnel.

gavenkoa
  • 45,285
  • 19
  • 251
  • 303