Monitoring must be done using the VM owner, the tomcat user on RHEL. In a VNC session, “xhost +SI:localuser:tomcat” or equivalent needs to be run to allow tomcat to access the DISPLAY.
First I needed to setup some things as root, as the tomcat user home directory is owned by root and jvisualvm wants to create some preference directories.
su -
mkdir /usr/share/tomcat5/.visualvm
mkdir /usr/share/tomcat5/.nbprofiler
chown tomcat:tomcat /usr/share/tomcat5/.visualvm
chown tomcat:tomcat /usr/share/tomcat5/.nbprofiler
Then, one can just run jvisualvm as tomcat when required:
su - tomcat
jvisualvm
To monitor a long running jvm owned by the tomcat user, you will also need to ensure that the tmpwatch program does not blow away an important jvm file:
- Edit the file
/etc/cron.daily/tmpwatch - Add the exclusion
-x /tmp/hsperfdata_tomcatto the /tmp tmpwatch invocation.