User Tools

Site Tools


set_up_jmx_and_jconsole

Metacat and KNB Web Maintenance โ†’ Set Up JMX and JConsole

Java Management Extensions (JMX) allow for monitoring and managing applications. The jvm (and applications) can make information available via management beans (MBeans). A great deal of information is automatically available from the JVM, such as thread information, memory usage, etc. The information can be gathered at the command line and made available to a monitoring system using a program called jvmstat. A gui program can be used to view the information real time as well. Here we will discuss using JConsole, which ships with sun java. โ€” Setting up JMX on the server โ€” You will need to add some java arguments to the startup command for Tomcat. If you have a catalina.sh in your <tomcat_home>/bin directory, you can add the args to CATALINA_OPTS. If not, there are different startup files for different tomcat installations, so you will need to decide where the additional arguments should live. The most important consideration is that the arguments show only during start/run commands somewhere before the org.apache.catalina.startup.Bootstrap element.

For more information on JMX configuration, refer to http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html <br> For more informtaion on JConsole client, refer to http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html

  • Add the following arguments to your CATALINA_OPTS in catalina.sh (or other location of your choice).
    • -Dcom.sun.management.jmxremote.port=8686 - You can choose a different port if this one conflicts
    • -Dcom.sun.management.jmxremote.ssl=false - Do not use ssl. You can change this to true if you like, but you will have to take care of exchanging ssl certificates.
    • -Djava.rmi.server.hostname=128.111.242.154 - This tells the rmi server to register itself against the server's ip. Use the phyiscal IP of the server.
  • add access - this configuration has password control. You can set the authenticate option to false and disable password protection.
    • Set up the password file
  • **If it does not already exist, copy <JAVA_HOME>/lib/management/jmxremote/jmxremote.password.template to jmxremote.password.
  • **Add a line at the bottom that looks like: 'webuser <web_user_password>', or whatever user password combo you want.
  • **Exit and save the password file.
  • **Change ownership of the jmxremote.password file to be the user that runs Tomcat: 'chown <tomcat_user> jmxremote.password'
  • **Change the permissions to be read/write by the owner only: 'chmod 600 jmxremote.password'
    • Set up the access file
  • **Edit <JAVA_HOME>/lib/management/jmxremote/jmxremote.access .
  • **Add a line at the bottom that looks like: 'webuser readonly' or 'webuser readonly' depending on what access you want to grant. You will need a line in this file for every line you created in the password file.
  • **Exit and save the access file.
  • **Change ownership of the jmxremote.access file to be the user that runs Tomcat: 'chown <tomcat_user> jmxremote.access'
  • **Change the permissions to be read/write by the owner only: 'chmod 600 jmxremote.access'
  • Restart tomcat
    • Check that the new parameters show up by typing: 'ps auxww | grep tomcat'
    • You should see all the parameters you entered above
    • They should all appear before org.apache.catalina.startup.Bootstrap
    • Make sure JMX is listening by typing 'netstat -an |grep 8686' (or your port). You should see that port listening.
  • Run a jconsole client against the server.
    • On a client machine, run '<JAVA_HOME>/bin/jconsole &'. You should see a gui console pop up with a 'Connect to Agent' dialog.
    • Go to the remote tab
    • Enter the host name, port, username and password for your server and hit connect.
    • You should see a summary window for the server
    • There are several things that can cause the connection to fail, but a common one is not having firewall access to the server. Fixing this is not graceful, since you have to have access to two ports: the one that JMX listens on and the RMI port that was set up dynamically by the server. Unfortunately, there is no easy way to set the port for RMI, so your client must pretty much be opened up on the server.
    • You can refer to the documentation above for what all the different tabs mean, but the memory tab is the most common section used for troubleshooting the JVM and GC.
set_up_jmx_and_jconsole.txt ยท Last modified: 2012/02/07 11:32 (external edit)