I've read Visual VM remotely over ssh but I think I've not fully understood because it was not working for me :-( Please can someone give some example?
ssh -D 9696 [email protected]
and visualvm.exe -J-Dnetbeans.system_socks_proxy=localhost:9696 -J-Djava.net.useSystemProxies=true
starts visualvm, but no processes of external machine are shown (only the local ones like visualvm itself). Moreover sometimes (but not always) I got the message "channel 3: open failed: connect failed: Connection refused" in my ssh window.
Any help?
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.)
With features like thread analysis and head dump analysis, it is very handy in solving run-time problems. VisualVM is free, and you don't need to pay a separate cost to get this.
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.
You either need to run jstatd on the remote side, or specify a JMX connection using host:port.
Jstatd:
jstatd -J-Djava.security.policy=permissions.txt [-p port]
After that: add a remote connection to the target machine, and on the properties of that remote connection configure the jstatd connection.
(permissions.txt contains for example this:
grant {
permission java.security.AllPermission;
};
Edit: (Answer to comment)
ssh -D 9696 me@remote
, and run jstatd as above on the remote command line. If you want jstatd to be on a different port than the default 1099, use the -p argument to jstatd.
run visualvm.exe -J-Dnetbeans.system_socks_proxy=localhost:9696 -J-Djava.net.useSystemProxies=true
on the local machine
in visual vm: add new remote connection, and specify remote as host and the port for jstatd (1099 for default, or what you specified with -p when running jstatd)
You should now see the processes on the remote side in visualvm
I have another solution using standard SSH tunneling and no firewall ports to open. For me, SOCKS proxy does not work.
Start your JVM with options:
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=[port1]
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.rmi.port=[port2]
The important part is "server.hostname=localhost". Additionally, you explicitly define both ports (connect + "random" RMI port), "jmxremote.rmi.port" needs at least Java 7 update 4 (I read somewhere, did not check this info - use "lsof -i" on your server machine to check the really used ports).
(Of course, you may use authentication or SSL.)
Connect via ssh to the server and forward your local port1 and port2 to localhost:port1|2 an the server.
In VisualVM open a JMX connection to localhost:port1 (without any proxy setting).
I was having the same issue while connecting jVisualVM to a remote application over ssh.
This Tutorial helped me solve my issue. http://issamben.com/how-to-monitor-remote-jvm-over-ssh/
To solve this issue make sure :
you set two port in the jvm configuration
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9011
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.local.only=false
ssh tunnel is properly established
ssh -i yourPermissionFile.pem -l username 101.101.101.101 -L 9010:localhost:9010 -L 9011:localhost:9011
I had the issue of jstatd binding on localhost, so i had to type
jstatd -J-Djava.security.policy=allPerm.policy -J-Djava.rmi.server.logCalls=true -p <port> -J-Djava.rmi.server.hostname=<my ip>
also for jvisualvm i use this parameters instead
jvisualvm -J-DsocksProxyHost=localhost -J-DsocksProxyPort=<socks-port>
this way, connecting by the ssh proxy, i could use the real ip address of my remote machine.
Stealing from this answer i made myself a full reminder on my site .. i hope you don't mind ankon Thanks for this by the way :)
I also found that the jvm arguments:
-J-Dnetbeans.system_socks_proxy=localhost:9696 -J-Djava.net.useSystemProxies=true
did not work on the build i am using 1.3.2.
Therefore I used the Tools > Options > Network and set it manually under the SOCKS settings.
BUT VisualVM did did still not find the remote processes. I then removed the "No proxy hosts" listening of localhost, since this probably blocked it.
I found that in the jvm arguments for the proxy do not work. At least in version 1.3.3 (build 111013). Setting the proxy in Tools > Options > Network worked for me. Also system wide proxy settings should work though by definition it affects all other network connections.
I know this question is old but i suggest the easier solution instead of using jstat.
just only use SSH and Jvisualvm
Use jvisualvm easy way to detect memory leak and monitor CPU, RAM of application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With