Skip to content

Instantly share code, notes, and snippets.

@yashdeeph709
Last active January 18, 2024 01:36
Show Gist options
  • Save yashdeeph709/20137f322df8c32851d836227694c08c to your computer and use it in GitHub Desktop.
Save yashdeeph709/20137f322df8c32851d836227694c08c to your computer and use it in GitHub Desktop.
How to connect visual vm java profiler over ssh tunnel through bastion/jump server.
Prerequisite : Public Key Setup is required for using this setup
1. First open ~/.ssh/config file and add these lines filling the appropriate details.
This will setup a netcat tunnel through jump server which will forward all your traffic to mail machine.
```
Host <HOSTNAME>
User <USERNAME>
HostName <HOSTNAME>
ProxyCommand ssh <JUMPSERVER-USER>@<JUMPSERVER-ADDR> nc %h %p 2> /dev/null
```
2. ssh -v -D :port: :username:@:hostname:
3. open visualvm which is inside $JAVA_HOME/bin/visualvm.exe
4. open Tools>options>Network
5. choose manual proxy setting
6. fill socks proxy only with values Host:localhost Port: <port in step 1>
7. Right click on remote host and add remote host.
8. enter hostname as ip:jmxport
9. Now you will see the profiler working for the required jvm.
For jmx configuration start your java application like this.
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -jar Notepad.jar
For remote sampling memory analysis is not possible for that you need to use jmap installed on same host.
@mrsolarius
Copy link

mrsolarius commented Jun 24, 2022

Maybe add .md at the end of your document to prettify him. ^^
(replace ProfilingOverTunnel by ProfilingOverTunnel.md)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment