Java Performance monitoring tool: VisualVM

Source: Internet
Author: User
Tags visualvm

VISUALVM is a free, integrated visualization tool that integrates multiple JDK command-line tools to provide you with powerful analytical capabilities for performance analysis and tuning of Java applications. These features include generating and analyzing massive amounts of data, tracking memory leaks, monitoring the garbage collector, performing memory and CPU analysis, and it also supports browsing and manipulation on MBeans. This article mainly describes how to use VisualVM (JVM monitoring) for performance analysis and tuning.

Since JDK 6 Update 7 has been part of the Oracle JDK, it is located under the Bin folder of the JDK root directory , without the need to install and run directly.

When you double-click Start Java VisualVM, you can see the "local", "Remote", "snapshot" three items in the "Application" bar on the left side of the window.

"Local" shows the resource usage of Java programs running on localhost, and if Java programs are running locally , start Java VisualVM to see the corresponding program name. Click on the program name to open the appropriate resource monitoring menu to graphically list the CPU, Heap, PermGen, class, and thread statistics that the program occupies.

"Remote" entry for the resource usage of the Java program on the remote host, but need to run the JSTATD daemon on the remote host

The VISUALVM is divided into 3 classes, which are automatically detected and displayed locally.

Now start idea.

Double click on any node under local, see the change on the right, you can monitor the CPU, memory, class, thread and other health, real-time monitoring server performance.

Right click VISUALVM we can see Thread dump, Heap dump

Do Thread Dump, and soon you'll see the results.

Heap dump takes a little time (you can see the number of objects in the heap and the proportions that are used to make OOM very useful)

two. Remotely monitor the JVM with VISUALVM

1. Install the JSTATD component on the server

The JSTATD tool is an RMI server application that monitors the creation and termination of a hotspot Java virtual machine and provides an interface to allow remote monitoring tools to be attached to a JVM running on the local host.

Install OPENJDK using the Apt-get command:

sudo apt-get install openjdk-6-jdk  

2. Configure the JSTATD security policy file on the server

JSTATD is an RMI (remote method invocation) server program that monitors the JVM's resource usage from creation to destruction and provides a remote monitoring interface, which is a Daemon program that requires the remote monitoring software to be connected locally The JSTATD remains running.

The jstatd operation needs to specify the security policy through-j-djava.security.policy=***, so we need to establish a file jstatd.all.policy on the server that specifies the security policy, with the following file contents:

"file:${java.home}/. /lib/tools.jar "{
Permission Java. Security. Allpermission;
};

3. Modify the IP address in the server Hosts file

For the Java VisualVM to successfully connect to the remote server, the server side should set the native address to the IP address of the native in the/etc/hosts file. Use the Hostname-i command to view, if the display is 127.0.0.1 or inconsistent with the native IP, you need to change the corresponding address in the/etc/hosts file to the native real IP.

4. Run the JSTATD daemon

JSTATD need to keep running, execute JSTATD program, command as follows:

Jstatd-j-djava.security.policy=jstatd.all.policy

5. Connect to server monitoring Java programs via Java VisualVM

On the left side of the Java VisualVM program window "Remote" Project right-click "Add Remote Host", enter the remote host's IP address in the popup dialog box, confirm the submission can see the corresponding remote host and Java program running above, the connection should display JSTATD and its Pid.

Right-click Remote Select to add a remote host:

If you re-specify the JSTATD port, select Advanced settings to modify the port, such as: default port is 1099

After adding:

Three: Tomcat configuration jmx

Use Hostname-i to see if it is 127.0.0.1, this step is very important, otherwise it will fail to connect, if yes, must be configured-djava.rmi.server.hostname such as my configuration for-djava.rmi.server.hostname= 192.168.8.7 without modifying the Hosts file, modifying this file may also affect other programs.
Just tomcat_home/bin/find catalina.sh with the following parameters, restart Tomcat:

java_opts="$JAVA _opts-djava.rmi.server.hostname=192.168.8.7  - dcom.sun.management.jmxremote.port=8088  -dcom.sun.management.jmxremote.ssl=false  - Dcom.sun.management.jmxremote.authenticate=false"  

Note: 1. -dcom.sun.management.jmxremote.port: This is the port number configured for the remote connection, to make sure that it is not occupied

2.-DCOM.SUN.MANAGEMENT.JMXREMOTE.SSL=FALSE Specifies whether JMX is enabled for SSL

3.-DCOM.SUN.MANAGEMENT.JMXREMOTE.AUTHENTICATE=FALSE Specifies whether JMX enables authentication (requires username, password Authentication)

2, 32 is a fixed configuration and is a remote service permission for JMX

4.-djava.rmi.server.hostname: This is the IP of the configuration server

Open the java_home/bin/under the JVISUALVM or Jconsole tools can be directly connected, such as VISUALVM connected:

You can also write a Java class Testjmxclient.java test if the JMX connection is successful:

ImportJava.util.HashMap; ImportJava.util.Map; Importjavax.management.MBeanServerConnection; ImportJavax.management.remote.JMXConnector; Importjavax.management.remote.JMXConnectorFactory; ImportJavax.management.remote.JMXServiceURL; /**  * @authorMichael*/   Public classtestjmxclient {/**      * @paramargs*/       Public Static voidMain (string[] args) {Try{String Jndipath= "Jmxrmi"; String ServerHost= "192.168.8.7"; String ServerPort= "8088"; //Url=service:jmx:rmi:///jndi/rmi://192.168.8.7:8088/jmxrmiString Jmxurl = "service:jmx:rmi:///jndi/rmi://" + ServerHost + ":" + ServerPort + "/" +Jndipath; System.out.println ("Jmxurl:" +Jmxurl); Jmxserviceurl URL=NewJmxserviceurl (Jmxurl); Map<string, object> envimap =NewHashmap<string, object>(); Jmxconnector connector=jmxconnectorfactory.connect (URL, envimap); Mbeanserverconnection MBSC=connector.getmbeanserverconnection (); System.out.println ("Successful Connected");              Connector.close (); System.out.println ("Close Connect"); } Catch(Exception e) {System.out.println ("Error");          E.printstacktrace (); }      }  }  

Reference:

http://ihuangweiwei.iteye.com/blog/1219302

http://sjsky.iteye.com/blog/705323

Http://www.cnblogs.com/wade-xu/p/4369094.html

Java Performance monitoring tool: VisualVM

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.