Using SSH Proxying with Jconsole to remote Cassandra instances

Posted in: Cassandra, Technical Track

This guide leans heavily on the work of — what I’ve done is collect his work into something a little more manageable for our environment.


This guide assumes a few things are set up:

  1. That you’ve got ssh keys pushed around to do passwordless logins between your machine and your intermediate client machine
  2. That you’ve got cassandra up and running remotely
  3. That cassandra is listening on 8080 for it’s JMX service port

The Meat

This hunk of bash script is the meat of making this work.  Put the following in your .bashrc.  Make sure to edit proxy_host= to match your environment.

function jc {
    # set this to the host you'll proxy through.
    proxy_host="[email protected] -p 22"    host=$1


    if [ "x$host" = "x" ]; then
        echo "Usage: jc <remote server> [proxy port]"
        return 1

    # 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

    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 \

    # tear down the tunnel
    kill $ssh_pid

Then, either close your shell, or source your .bashrc.  Then you should be able simply to call your function like so:

    host$ jc cassandra-host01

Jconsole will pop up, and log you in.


Originally available at



Want to talk with an expert? Schedule a call with our team to get the conversation started.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *