viernes, 6 de febrero de 2015

jconsole and VisualVM over ssh tunnel on EC2 for Tomcat 7 using JMX

Hi, today I will talk about how to do a tunnel using ssh in order to monitor Apache Tomcat 7 using JMX in four simple steps.

Let's suppose:

  • Your Apache Tomcat 7 server is installed on Amazon EC2 platform
  • You want to monitor Tomcat from your Mac OS computer (or Linux) without having installed jconsole on EC2

Then, do the following.

1) On the EC2 server side assign the CATALINA_OPTS variable (and export it):

$CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

2) Restarts Apache Tomcat

3) Start the ssh tunnel:

ssh -D9999 -i your_keyfile.pem ec2-user@your_domain_name.com

4) On the client side, open a terminal and execute the following:

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

That's it!!

PS. Remember to adjust it according the ports you want
      For VisualVM, do not forget to configure the SOCKS proxy and pay attention to the option No Proxy Hosts in case of localhost