If you are a Tomcat administrator, then you should be familiar with how to enable JMX in tomcat to monitor Heap Memory, Threads, CPU Usage, Classes, and configure various MBeans. In this article, I will talk about how to enable and connect to Tomcat with JConsole. I assume you have Tomcat installed if not; you can refer installation guide.
Go to path where you have Tomcat installed Go to bin folder Create a file as “setenv.sh” Modify file using vi editor and add following
Save the file with “:w” Change the file permission as executable
Before you start Tomcat to verify JMX, let’s take a look at the above configuration. Let’s start the tomcat by startup.sh script file. Once started, you can verify either using netstat or ps –ef grep command.
To verify using netstat
netstat –anlp | grep 9000
To verify using ps command
ps –ef |grep jmx This concludes jmx is enabled in Tomcat and it’s time to connect using JMX client. You may use any client, however, to show you I will use jconsole, which comes with java.
Connect Tomcat JMX using Jconsole
Go to the path where you have jconsole
Tip: you may use the find command to search if you are not sure.
Execute jconsole
This will popup Java Monitoring & Management Console.
Select “Remote Process” Enter the server host and port details
Click on “Connect”
This will connect to Tomcat and show you very nice graphs of CPU, Memory & Thread usage. This becomes very handy during troubleshooting.
You may also perform GC from the console.
Click on Memory tab, and you will see “Perform GC” button
As mentioned at the beginning of the article, you may also configure MBeans for the classes. This is often used if you have to change the logging or specific parameters at runtime. So go ahead and play around with Jconsole and JMX. It’s a wonderful tool for troubleshooting and monitoring. If you are interested in learning more about Tomcat, then check out this tutorial.