Cannot connect jmx to java app running in docker on remote host - java

Assuming I have a server in my local network with ip 192.168.100.10.
There is docker container running in it with java application.
Now i want to connect to this java application with VisualVM from my computer which has ip address 192.168.100.20. I thought I had everything configured properly but it still does not work.
I have passed these JVM options:
-Dcom.sun.management.jmxremote"
-Dcom.sun.management.jmxremote.port=9010"
-Dcom.sun.management.jmxremote.authenticate=false"
-Dcom.sun.management.jmxremote.ssl=false"
-Dcom.sun.management.jmxremote.local.only=false"
-Dcom.sun.management.jmxremote.rmi.port=9010"
-Djava.rmi.server.hostname=192.168.100.10"
Then I have exposed port 9010 in Dockerfile:
EXPOSE 9010
Then added this port to docker-compose:
ports:
- "9010:9010"
I am trying to connect to remote host with JConsole or VisualVM from my local machine. In "Remote Process" input in JConsole I put "192.168.100.10:9010" but connection fails with error:
"The connection to 192.168.100.10:9010 did not succeed. Would you like to try again?"
What am I doing wrong?

The solution above is sufficient and working. I've been using env variable to set port number which was not working properly.

Related

How connect to db when running Dockerfile?

I have a spring boot app that connects fine to my PostgreSQL server running locally in Desktop Docker.
Than I wrote a simple Dockerfile to run my app in container. Container starts but can't connect to my db server with error message:
Connection to localhost:5432 refused.
Why and how to fix this?
To access localhost from inside a docker container you can use the IP of your computer. Localhost or 127.0.0.0 donsen't work.
Use docker compose to connect the two docker containers.
https://docs.docker.com/compose/
On this page you can see an example on how to connect to containers using docker compose:
https://dev.to/mozartted/docker-networking--how-to-connect-multiple-containers-7fl
If they are on seperate Docker networks, use:
docker.host.internal
This connects to the Docker host machine. So if your PostgreSQL instance is exposed on 5432, docker.host.internal will route to that instance through the host from other containers.
Alternatively, set them up in the same network using docker compose or by creating a network and attaching both containers to them. They can then communicate with container name.
https://docs.docker.com/engine/reference/commandline/network_create/

How to connect to local application via jconsole using remote process?

I have ordinary spring boot application and am able to connect to that application using jconsole when I choose it from the Local Processes group:
But I want to connect to my application remotely. Firstly I want to connect from the same PC but using remote process.
I tried to type localhost:1099 and localhost:1199 but it doesn't connect:
I didn't pass any special VM keys.
How can I connect using remote process?
The monitored application must be started with following java runtime arguments:
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=1199
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
Then in JConsole you can connect to remote process using localhost:1199.
I was able to connect when I used port from -Dcom.sun.management.jmxremote.port

VisualVM jstatd remote connection

I am running a tomcat on a remote Linux server. I want to connect it with VisualVM from my laptop with following steps:
start jstatd with jstatd -J-Djava.security.policy=/path/to/jstatd.all.policy, refer to cannot start jstatd due to permission error
start jvisualvm on my laptop
add remote host with IP, but no applications appears under the IP node. I can telnet IP 1099 from my laptop.
How to debug the issue?
Fixed the issue by steps from Blog: Profiling remote JVM using VisualVM
If VisualVM doesn’t list the remote jvm’s, here are some tips in getting it working:
Binding issues: sometimes jstatd doesn’t bind to the correct ip address. You can force binding it to a specific ip using something like
-J-Djava.rmi.server.hostname=10.1.1.123
You can check other parameters from the blog above if you still have the issue.

jprofiler jpcontroller can't connect to jvm when called with host:port

i want to profile my web application now this is what i do:
run jpenable.exe and after it finds thi jvm, it gives me a port so i can connect to it using JProfiler GUI(for instance:12121)! now as I want to have commandline control i then try to connect jpcontroller using this command:
jpcontroller.exe localhost:12121
but it cannot connect and sticks there with no error! now if i use this command:
jpcontroller.exe <port>
then it works!
but actually i can't do this as i want to connect to a remote jvm!!
am i wrong some where?
jpcontroller does not connect to the port that is opened by the profiling agent, but it uses JMX to connect to the process. For that to work on a remote computer, add the VM parameter
-Djprofiler.jmxServerPort=[port]
to the profiled process and use that port in jpcontroller. Then, an MBean server will be created that listens on that port.

Remote Debugging in eclipse

I have an application running in server A. The dev environment is in server B.
I am trying to do remote debugging of app running in server A.
In server A i added following command to service start script
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4554,server=y,suspend=n
And service is running in server A.
When i try to launch remote debugging configuration it gives
Failed to connect to remote VM. Connection refused. Connection refused
port 4554 is free in server A.
What other configuration need to be done for this?
Regards
Dheeraj Joshi
Try this.
Set suspend=y, just to make sure you got the JVM line right. This should stop the VM on startup until you connect.
If you're on Unix, bring up the terminal and try telnet [host] [port] - this will quickly let you know if there's anything listening to that port on that host.
Make sure the connection properties in Eclipse are set correctly. Note that the port defaults to 8000.
Use the IP address instead of the host name, to rule out DNS/hostfile problems.
Another way of starting the JVM that I use successfully is:
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y
Check if there is a firewall between and/or on the two servers.

Categories