Skip to content

Instantly share code, notes, and snippets.

@jeromatron
Created August 5, 2011 21:57
Show Gist options
  • Save jeromatron/1128625 to your computer and use it in GitHub Desktop.
Save jeromatron/1128625 to your computer and use it in GitHub Desktop.
jmx/jconsole shell function
# jmx/jconsole tunneling shell function - add to .profile
#
# usage: jmx [keypair] [remote host] [remote port]
# example: jmx /keys/keypair.pem [email protected] 8080
function jmx() {
keypair=$1
remote_host=$2
remote_port=$3
proxy_port=10999
ssh -i $keypair -f -D$proxy_port $remote_host 'while true; do sleep 1; done'
ssh_pid=`ps ax | grep "ssh -i $keypair -f -D$proxy_port $remote_host" | awk '{print $1}'`
jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=$proxy_port service:jmx:rmi:///jndi/rmi://0.0.0.0:$remote_port/jmxrmi
kill $ssh_pid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment