Introduction
Sometimes it can be useful to monitor performance of Java Virtual Machine (VM) on remote host. To do so, a very nice tool – VisualVM – can be used. It can be run on local host and get information from jstatd running on a remote host. In addition, VisualVM comes with a number of useful plugins. This blog describes how to run VisualVM with VisualGC, which is Visual Garbage Collection Monitoring Tool to monitor Tomcat on remote machine. However, the solution can be also applied to other applications running on JavaVM.
Remote machine
Run Tomcat
Add the following options to CATALINA_OPTS
variable to enable JMX support in Apache Tomcat.
in my case:
You can find more information about Monitoring and Managing Tomcat here: Monitoring and Managing Tomcat
Run Tomcat:
We want to monitor Tomcat instance running on remote machine. To check whether it is running use:
The above command run on my remote machine returns the following:
Notice that pid is ’28743′.
To get JavaVM process status you can run jps
command, which is Java Virtual Machine Process Status Tool. jps
is located is your Java JDK HOME/bin
directory. Description of jps
command can be found here. Note that jps
returns only Java processes run by the user, who runs jps
. To get list of all Java processes run sudo jps
. See examples below.
Outcome of jps
run on my remote machine:
Outcome of sudo jps
run on my remote machine:
Notice that lvmid for Tomcat (in this case – Bootstrap) is ’28743′ which is the same as pid.
Hostname
Run
to check the host name, e.g., agile003
.
Make sure that in /etc/hosts
file this hostname has IP by which it is visible to the machine that will be running VisualVM (local machine), e.g., 192.168.1.20 agile003
.
Run jstat Deamon
jstatd
, which is jstat Daemon can be found in Java JDK HOME/bin
. As described in documentation to jstatd, which can be found here: , create a file called jstatd.policy in any directory you choose, e.g., /home/joanna. The file should contain the following text:
Run jstatd using the following command. Make sure you run it with root permissions.
You can add the following flag to log the calls and see what is going on:
Local machine
Check access to jstatd
Run:
in my case
You should see the same output as for sudo jps
running on remote machine.
Run VisualVM
Run:
or
jvisualvm
can be located in your Java JDK HOME/bin
directory also it can be downloaded from here: JVM download
Go to
and install the plugins you require including VisualGC plugin. My selection is presented in the screen shot below.
Restart VisualVM.
Add remote host – one that jstatd
is running on.
give IP of the host, e.g., 192.158.1.20. The same IP should be set for the host name in /etc/hosts
on remote server.
Now you should be able to access the Java processes running on remote host including Tomcat as presented below.
All tabs including VisualGC on right hand site should now show appropriate graphs. See sample screen shot below:
Enjoy!