Detailed Java Virtual Machine (viii) ------ virtual machine monitoring and analysis tools (2) - Visualization

  Part blog we introduced the virtual machine monitor and analyze the command-line tool , due to its intuitive enough, not very easy to troubleshoot the problem, then we have to introduce this blog several visualization tools.

1、JConsole

  JConsole (Java Monitoring and Management Console) is a JMX-based visual monitoring and management tools. It is part of the management functions are managed for JMX MBean, MBean can use the code, middleware server management console or all eligible JMX standard software to access it.

  JMX (Java Management Extensions) is a management function for the implant application framework, a standard set of agents and service; MBean is a kind of standard JavaBean, through integration and implementation of a set of standard interfaces Bean.

①, start JConsole

  This is our own JDK monitoring tools can be found in the bin JDK installation directory.

  When configured JDK environment variables, command prompt, type jconsole the CMD can also be opened directly.

  

  This is an executable file, simply double-click to open. Open as follows:

  

②, monitoring interface presentation

  JConsole monitoring tool that can monitor the local process and a remote process, we are here to monitor the local process, for example, to introduce specific monitoring interface.

  Click on any of the following local process column, go to the monitor screen.

  1. Monitoring At a Glance

  

  This interface is the first page after we establish a local connection, enter. It shows an overview of the entire virtual machine main operating data, including the "stack usage", "thread", "class", "the CPU usage" and four graph information, behind these graphs is "Memory", " thread "," class "tab information summary, the following will introduce several tabs, respectively.

  2, the memory monitor

  This tab is equivalent jstat command on the introduction of a blog, but here is visualization. Some trends for monitoring virtual machine memory.

  Monitoring the following areas:

  

  3, the thread monitor

  This tab is equivalent to visualize jstat command on the blog post describes. Thread encountered pause when you can use this tab to monitor the analysis.

  

  In addition, the lower left corner of this page there is a deadlock detection button, thread deadlock after emergence, click this button, there will be a new deadlock tab.

  For example, for this deadlock following codes:

 1     @GetMapping("/test2")
 2     public void test2() throws Exception{
 3         Object lock1 = new Object();
 4         Object lock2 = new Object();
 5 
 6         new Thread(()->{
 7             synchronized (lock1){
 8                 try {
 9                     Thread.sleep(1000);
10                 } catch (InterruptedException e) {
11                     e.printStackTrace();
12                 }
13                 synchronized (lock2){
14                     System.out.println("线程1结束运行");
15                 }
16             }
17         }).start();
18 
19         new Thread(()->{
20             synchronized (lock2){
21                 try {
22                     Thread.sleep(1000);
23                 } catch (InterruptedException e) {
24                     e.printStackTrace();
25                 }
26                 the synchronized (lock1) {
 27                      System.out.println ( "end of the thread run 2" );
 28                  }
 29              }
 30          .}) Start ();
 31 is      }

  Created here two locks, lock1, lock2, creates two threads, thread 1 after obtaining the lock1, say you give me lock2, I will release lock1; and after the thread 2 get to lock2, say you give me lock1, I releases lock2. Who does not release the two threads, so they caused a deadlock.

  It can be detected by monitoring tools, as follows:

  

  4, the class monitor

  

  5, VM Summary

  Show some JVM information.

  

③, remote monitoring and configuration of Tomcat

   In fact, the use of monitoring tools, we rarely monitor the local program, for the most part are deployed on a remote Linux server monitoring, then you want to use this tool JConsole for remote monitoring, we have to make some configuration . We first introduced remote monitoring of Tomcat.

  1, the configuration catalina.sh

  Add the following information in the configuration file:

JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=192.168.146.200 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

  -Dcom.sun.management.jmxremote indicate on remote connection.

  -Dcom.sun.management.jmxremote.port = 9004 indicates 1099 to set up a remote connection port

  -Dcom.sun.management.jmxremote.authenticate = false indicates that no password verification

  -Dcom.sun.management.jmxremote.ssl = fals indicates that no open connection ssl

  -Djava.net.preferIPv4Stack = true indicates that only supports IPV4 address

  -Djava.rmi.server.hostname = 192.168.146.200 192.168.146.200 represented monitored host name

  Add the following location:

  

 

  2, to establish a connection

  By the above configuration, start Tomcat, we only need remote connectivity interface JConsole, enter 192.168.146.200:9004, then click on the connection.

  

  3, connection error conditions

  If you can not connect, it is necessary in order to detect the following information:

  ①, port configuration can not be occupied by netstat -tunlp | grep 1099 command to verify.

  ②, turn on the firewall set above the port trust

  ③, by hostname -i command, ip address if not previously set printing, the need vim / etc / hosts command to modify the native IP address 127.0.0.1.

④, configure remote monitoring jar package

  Command to start the jar package is as follows:

nohup java -Djava.rmi.server.hostname=192.168.146.200 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1089 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar jvm-0.0.1-SNAPSHOT.jar &

  Configure port, ip address, and remote monitoring, Tomcat is substantially the same, and then establish a connection.

 2, JVisualVM

  English Introduction to All-in-One Java Troubleshooting Tool. Listen to the name we know this is a feature very wide, very powerful Java runtime monitoring and troubleshooting tools, and is the official virtual machine troubleshooting tools focus on the development of its performance analysis software than many professional fees will not be much less.

①, start JVisualVM

  And JConsole tool as described previously, this is a tool that comes with JDK, in the installation directory bin, you can simply double-click to start.

  

  Open the interface is as follows:

  

②, monitoring interface presentation

  In fact, the general interface and JConsole almost.

  

  Sampling can monitor detailed statistics on CPU, memory.

  

③, plug-in mechanism

  JVisualVM more powerful place with a variety of plug-ins can be installed to provide a variety of functions.

  Click on the top menu bar Tools --- "plug-in:

  

  Then set the plug-center address:

  

  This address, we can get up to this URL:

  https://visualvm.github.io/pluginscenters.html

  When you select the corresponding plug address to be selected according to our version of the JDK.

  For example, my side of the JDK version as follows:

  

  Then follows the selected address (152, between 131-221):

  

  After setting Download our side select the plug you need, click install it! For example, commonly used plug-Visual GC (GC used to view the log)

  

   After the installation is complete, we will be able to see this new plug-in on tab.

  

④, configure a remote connection

  Whether or remote connections Tomcat jar package, and introduced JConsole are exactly the same, please refer to the above configuration.

⑤, use the document

  For JVisualvm, the official Chinese have detailed documentation, as follows:

  https://visualvm.github.io/documentation.html

  

Guess you like

Origin www.cnblogs.com/ysocean/p/11415514.html