Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use VisualVM and JMX?

I have tried every recipe in the book, but things just wont work today...

I am trying to use VisualVM to profile my Java app running in a remote server, so I googled and googled and googled for ways to do this and I end up with this solution:

java -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=9199 \
  -Dcom.sun.management.jmxremote.local.only=false \
  -Dcom.sun.management.jmxremote.authenticate=false \
  -Dcom.sun.management.jmxremote.ssl=false \
  -jar bin/felix.jar

Running this will get me JMX to run I guess, so I can see him running on 9199:

java      21947        root    9u  IPv6 1811434      0t0  TCP *:7192 (LISTEN)
java      26376        root   14u  IPv6 1844518      0t0  TCP *:9199 (LISTEN)

Moreover, I can test that the port is visible on the web:

enter image description here

Now, when I try to open the connection in VisualVM in my machine (which can also ping the jmx server) this happens:

enter image description here

enter image description here

enter image description here

I must be so dumb, that everyone in this world was able to put this thing running but me. Damn...

EDIT: I installed wireshark to know what's going on under the hood, so I saw this. As soon as I add a remote IP in VisualVM wireshark starts detecting this repetitive activity:

enter image description here

However, if I try to add a new JMX connection and ask him to connect, wireshark will not grab even one single packet of that connection attempt.

enter image description here

This seems to me that VisualVM is not even trying to connect, despite giving the error message "Cannot connect"...!! What the hell is going on?

like image 880
PedroD Avatar asked May 07 '15 14:05

PedroD


People also ask

How do you use VisualVM?

To install a VisualVM plugin:Choose Tools > Plugins from the main menu. In the Available Plugins tab, select the Install checkbox for the plugin. Click Install. Step through and complete the plugin installer.

How do I monitor remote JVM using VisualVM?

There are two ways to connect a remote JVM application to VisualVM: Either using jstatd or Java Management Extensions (JMX). The jstatd program is an RMI server that bundled with the JDK and monitors JVM and provides an interface to allow remote monitoring tools to attach to JVM running on the localhost.

How do I connect to a VisualVM remote server?

Connecting to a Remote Host To add a remote host, right-click the Remote node in the Applications window, choose Add Remote Host and type the host name or IP address in the Add Remote Host dialog box. (You can also specify a display name that will be used to refer to the host when listed under the Remote node.)


1 Answers

Follow the below steps.
1) Go to remote machine open X11 forwarding,
2) Installed XMING in windows
3) Start visual VM in Remote machine the GUI will come in your windows xming.
4) Instead of IP use localhost and use same port number.

If above steps not working it means something is wrong with configuration.
If above steps working fine then go to iptables and ensure port 9199 open for outer world. as well start the program with java -Djava.rmi.server.hostname=YOUR_IP

For more details refer this link

like image 123
prashant thakre Avatar answered Oct 27 '22 06:10

prashant thakre