VisualVM cannot connect to any port except for 1099

11/21/2019

I have a remote jvm application running inside docker container managed by kubernetes:

java -jar /path/to/app.jar
  -Dcom.sun.management.jmxremote  
  -Dcom.sun.management.jmxremote.authenticate=false
  -Dcom.sun.management.jmxremote.ssl=false
  -Dcom.sun.management.jmxremote.local.only=false
  -Dcom.sun.management.jmxremote.port=1099
  -Dcom.sun.management.jmxremote.rmi.port=1099
  -Djava.rmi.server.hostname=127.0.0.1 

When I try to debug using port forwarding and VisualVM, it works only when I use port 1099 on local machine. Ports 1098, 10900, or any other don't work. This one works for VisualVM: kubectl port-forward <pod-name> 1099:1099. This one doesn't: kubectl port-forward <pod-name> 1098:1099

I use "Add JMX Connection" option in VisualVM, connecting to localhost:1099 or localhost:1098. The former works, the latter doesn't.

Why can't I use non-1099 ports with VisualVM?

UPD I believe the issue is related to VisualVM, because port forwarding seems to work fine whatever local port I choose:

$ kubectl port-forward <pod> 1098:1099
Forwarding from 127.0.0.1:1098 -> 1099
Forwarding from [::1]:1098 -> 1099
Handling connection for 1098
Handling connection for 1098
-- Ernest Sadykov
docker
jvm
kubernetes
visualvm

1 Answer

11/21/2019

The full JMX URL for connecting to localhost is as follows:

service:jmx:rmi://localhost:<port1>/jndi/rmi://localhost:<port2>/jmxrmi

...where <port1> is the port number on which the RMIServer and RMIConnection remote objects are exported and <port2> is the port number of the RMI Registry.

For port 1098 you could try

service:jmx:rmi://localhost:1098/jndi/rmi://localhost:1098/jmxrmi

I'd guess that both ports default to 1099 if not explicitly configured.


EDIT: Per the comments, the JMX URL that worked was:

service:jmx:rmi://localhost:1098/jndi/rmi://localhost:1099/jmxrmi
-- apisim
Source: StackOverflow