How to collect performance data with VisualVM and JMX

  • Updated

Objective

Remote monitoring and collection of performance data using JMX and VisualVM for a Java environment.

Process

1. Either on the problematic system or on a remote system install the VisualVM software for data collection. 

VisualVM is an app for Windows/Mac/Linux: https://visualvm.github.io/download.html

2. For the Java environment being monitored.  The following JVM properties are needed (more information on these can be found here). Make sure to add these BEFORE the javaagent:

-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9011 <not needed in most cases>
-Djava.rmi.server.hostname=<server IP address, really only needed if there are multiple Nic cards>
-Dcom.sun.management.jmxremote.local.only=false
Note! Port 9010 will be used later when connecting to the hostname/port defined with VisualVM

The following example shows the properties along with the Java agent:

java -Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.rmi.port=9011 \
-Djava.rmi.server.hostname=192.168.1.27 \
-Dcom.sun.management.jmxremote.local.only=false \
-javaagent:./contrast.jar \
-Dcontrast.config.path=contrast_security.yaml \
-jar webgoat-container-7.1-exec.jar \
-httpPort 8082

3. Start up the Application and check to ensure the 9010 port is listening. 

netstat -tupln
Note! If running remotely you may need to open up the systems firewall to allow the connection from VisualVM.

4. Launch VisualVM and add a Remote Host:

mceclip1.png

5. Then add the JMX Connection:

mceclip2.png

6. Once connected you will start seeing live threads within the JVM along with Contrast:

mceclip3.png

7. Click on the Sampler tab, then select the CPU button to start collecting data on CPU performance:

mceclip4.png

8. Recreate the performance problem while this is running.

9. Once recreated selectmceclip5.png and export the data

mceclip6.png

10. To collect Thread data select the Threads tab and select Thread Dump:

mceclip8.png


This will open a separate tab where all the text should be copied and pasted into a text document:

blobid0.png

11. Lastly to collect details on the environment.  Right click on the Remote Host connection and select Application Snapshot:

mceclip9.png

This will show up under the snapshots menu, right click and save this:

mceclip10.png

12. At this point you should have collected the CPU snapshot, thread dump and application snapshot. These should be zipped up and sent to support.  If the resulting files are large, ask your support rep for a SendSafely link to post them to.

See also:

 

 

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request