When the load on the Confluence server is high and Confluence is slow you will have to know what the application is doing. You can always take some thread dumps but these are not always enough. VisualVM is a great tool for debugging and profiling a JVM.
In order to connect to a remote Atlassian Confluence instance via JMX you need to follow the steps below. In this scenario I am connecting to a Confluence 6.11 on a remote server.
Find the Tomcat version bundled with your Atlassian Confluence
Log into the Linux server and go to <CONFLUENCE-INSTALL> folder. Look in the RELEASE-NOTES file. Here you will find a text like this ‘Apache Tomcat Version 9.0.10’ in the top of the file.
Stop the Confluence Server
Now that we know the Tomcat version stop the Confluence server.
Download the correct catalina-jmx-remote.jar to the <CONFLUENCE-INSTALL>/lib folder
We need a jar file that contains a JMX remote listener Java class that needs to be wired up. Go to the <CONFLUENCE-INSTALL>/lib folder and download the tomcat catalina-jmx-remote.jar like this:
Notice that this jar is a part of the Tomcat extras bundle and the jar version is the same as the bundled Tomcat version we found earlier.
Configure a Listener element in server.xml file
Go to the <CONFLUENCE-INSTALL>/conf folder and edit the server.xml file. Use your favorite editor. Now we need to insert a Listener element.
The className attribute contains Java class that we need, rmiRegistryPortPlatform and rmiServerPortPlatform attributes contains the same port which is OK. Insert this element in the Context element where Confluence instance is defined, do not use Confluence synchrony context. See screenshot below how the element is inserted.
Save the server.xml file with the Listener element.
Insert JMX parameters in setenv.sh in <CONFLUENCE-INSTALL>/bin folder
Now that Tomcat is configured with a JMX listener we need to add some parameters to the setenv.sh file in <CONFLUENCE-INSTALL>/bin folder. Open the setenv.sh file with your favorite editor and append the following lines to the existing CATALINA_OPTS lines and just before the export CATALINA_OPTS line:
WARNING: We have no authentication here but do consider using JMX authentication if your JMX profiling take several days, hopefully not. See this link for setting up authentication on remote connection.
Start the Confluence Server
Tunnel to the Confluence Server
Now create a SSH tunnel to the Confluence server so that we can boot up VisualVM locally and connect to 10002 on localhost.
Download and start VisualVM
Download VisualVM from https://visualvm.github.io and start the application. VisualVM can run on Windows, Linux and Mac so no need to worry. Click the Add JMX Connection button and add localhost:10002 to the tunnelled local port. Make sure to check 'Do not require SSL connection' as we set the CATALINA_OPTS="-Dcom.sun.management.jmxremote.ssl=false.
Now we can start monitoring the Confluence application.