I’ve been working with Cassandra recently and wanted to start using JConsole. JConsole exposes some pretty useful information about Cassandra and the Java environment in which it runs. It operates over JMX and by default it only accepts connections from the localhost. Since we don’t run GUIs on our servers and we didn’t want to open up the JMX service to remote connections we needed to do a little wizardry to connect. First I thought of tunneling over ssh;

ssh -N -L 7199:localhost:7199 remotehost

This is a pretty standard way to connect a service that only listens for connections from the localhost. However this would not work at all. After much troubleshooting I came across a solution.

The solution was to connect via a SOCKS proxy;

ssh -fN -D 7199 remotehost

This essentially setup up a proxy, running on port 7199 (this can be anything, it does not have to match the JMX port), to the remote node (cassandra in this case). Then we can connect with JConsole like so…

jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=7199 service:jmx:rmi:///jndi/rmi://localhost:7199/jmxrmi -J-DsocksNonProxyHosts=

This allows JConsole to connect to the JMX service running on the remote Cassandra node;

[caption id=”attachment_2353” align=”alignnone” width=”1800”] JConsole connectted via JMX to a remote Cassandra Node with a SOCKS proxy[/caption]