Created
August 28, 2013 17:27
-
-
Save EnigmaCurry/6368753 to your computer and use it in GitHub Desktop.
Cassandra remote jconsole through SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function jc { | |
host=$1 | |
proxy_host="$1 -p 22" | |
# Find just the hostname (if specified as user@host): | |
host=`echo $host | sed 's/.*@//'` | |
jmxport=7199 | |
proxy_port=${2:-8123} | |
if [ "x$host" = "x" ]; then | |
echo "Usage: jc [<user>@]<remote server> [proxy port]" | |
return 1 | |
fi | |
# start up a background ssh tunnel on the desired port | |
ssh -N -f -D$proxy_port $proxy_host | |
# if the tunnel failed to come up, fail gracefully. | |
if [ $? -ne 0 ]; then | |
echo "Ssh tunnel failed" | |
return 1 | |
fi | |
ssh_pid=`ps awwwx | grep "[s]sh -N -f -D$proxy_port" \ | |
| awk '{print $1}'` | |
echo "ssh pid = $ssh_pid" | |
# Fire up jconsole to your remote host | |
jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=$proxy_port \ | |
service:jmx:rmi:///jndi/rmi://${host}:${jmxport}/jmxrmi | |
# tear down the tunnel | |
kill $ssh_pid | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment