How to use VisualVM and JMX?
Asked Answered
G

3

11

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?

Guardi answered 7/5, 2015 at 14:34 Comment(4)
Maybe this does the thing - make sure your host IP is configured properly https://mcmap.net/q/202598/-remote-jmx-connectionHurtle
I've tried that before :( nothing seems to work, despite the port being visible to the web.Guardi
Out of curiosity is there a firewall between your desktop and the process that has JMX enabled? I know you say port 9199 is open; however, JMX requires a 2nd port that is randomly assigned and is non-configurable. This causes huge problems when trying to use JMX through a firewall. Probably not your problem just throwing it out there as something to look at: blogs.oracle.com/jmxetc/entry/…Beware
I am not aware of any firewall being present. the sysadmins responsible for the network say that there is no firewall in between. JMX must be a close relative to the DCOM technology. How can they turn such simple things into over engineered and non-working solutions... damn...Guardi
U
4

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

Unshroud answered 9/5, 2015 at 11:3 Comment(0)
K
11

Start your service using these options:

-Djava.rmi.server.hostname=193.163.XXX.XXX
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9199 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

Then you can use jvisualvm or jconsole with just the "193.163.XXX.XXX:9199" address.

Karttikeya answered 9/5, 2015 at 12:34 Comment(0)
U
4

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

Unshroud answered 9/5, 2015 at 11:3 Comment(0)
J
0

Please use the following JVM options :

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=<PORT> -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<IP>

In the VisualVM use the following to connect:

service:jmx:rmi:///jndi/rmi:/<IP>:<PORT>/jmxrmi

Hopefully this will help.

Jahdiel answered 7/5, 2015 at 14:38 Comment(7)
Thanks for the suggestion. It didn't work, gives the exact same error message. i.imgur.com/Cm46gpM.png i.imgur.com/yrTAFIv.png The port 9199 is still accessible world wide.Guardi
Have you used the java options which I have provided. It's slightly different from yours : -Djava.rmi.server.hostname=<IP>Jahdiel
Yes. java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9199 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=193.136.102.224 -jar bin/felix.jarGuardi
And in VisualVM: service:jmx:rmi:///jndi/rmi:/193.136.102.224:9199/jmxrmiGuardi
If you do "ps -ef | grep jmx", are you able to see your process? However, it will work only in unix server. This is to just make sure that the process starts with JMX hook. Another suggestion, please don't mention the IP in this post. I have found that this IP is reachable over the internet.Jahdiel
I am unable to edit the previous comments to hide the IP. The response to that command can be seen here: pastebin.com/z8DmHhyX Is there a way to put code in these comments?Guardi
Sorry that I am not able to help you. Could you please try hawtio : hawt.io/getstarted . In short it exposes JMX over HTTP. I have used to monitor tomcat. As per the documentation you need to do something like this: java -jar hawtio-app-1.4.50.jar --port 8090Jahdiel

© 2022 - 2024 — McMap. All rights reserved.