java application monitoring (5) - visual monitoring tools

tags: java, troubleshooting, monitor,jvisualvm,jconsole


Summarized in one sentence: jdk comes with its own monitoring tools jconsole and jvisualvm easier and more intuitive for java application performance monitoring, below explaining how to use them.

1 Introduction

Previous articles (see below under "Related Reading") has to jdk command-line tool were introduced, but they are not enough to use a relatively intuitive, and generally requires the use of the machine, there is no easier and more intuitive way to monitor the java application? In fact, jdk itself already provides monitoring of java GUI tools, respectively jconsole, and jvisualvm, the following function and use of these two tools are described.

2 jconsole use

jdk jconsole is a built-in Java Performance Analyzer, installation bin directory of the JDK, under the windows, from the command line ( jconsole.exe) or simply double-click jconsole.exe up and running. Interested readers can refer jconsole tool of official documents use :https://docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html

2.1 two connections

When jconsole starts, it will provide two connections, which are connected to a local process and a remote connection process. It will directly list the local java process to select. If the need to monitor remote java process, then check the remote process, and enter: It needed a remote java process starts, set the remote JMX connection parameters, otherwise it is not connected, on JMX technology remote connection, refer to the official article ( ) https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.htmlparameters are as follows:

# 需要监控的服务器IP
-Djava.rmi.server.hostname=192.168.222.10

# 提供监控的java进程端口
-Dcom.sun.management.jmxremote.port=9004 

# 指定后续的通讯端口,与上面一致
-Dcom.sun.management.jmxremote.rmi.port=9004 

# 不使用ssl登录,若有安全需求,可设置
-Dcom.sun.management.jmxremote.ssl=false 

# 不验证,若有安全需求,可设置
-Dcom.sun.management.jmxremote.authenticate=false 

复制代码

As shown below:

Note that, because they do not use ssl, you are prompted to "unsafe", tap on it.

2.2 jconsole feature uses

After starting the process and connect java, jconsole interface is relatively simple, is divided into six modules:

  • Overview: general overview of the java process, including changes in the line graph heap, threads, class, CPU occupancy rate.
  • Memory: display heap and non-heap memory usage information, similar to jmap and jstat
  • Thread: Thread display usage information, similar jstack
  • Class: class loading information display
  • VM Summary: Display JVM information, similar jinfo
  • MBeans: MBeans Display information (with less than)

2.2.1 Overview

Overview of the main stack display, change the line graph the number of threads, class, CPU usage, basically you can directly view the application profile based on a line chart. If the heap memory for a high number of threads many activities, high CPU usage, you can go directly to the appropriate area to see the details to find the reason why. Further, right-click the corresponding graph, the data can be exported into a csv file is analyzed. Figure:

2.2.2 Memory

Memory is our monitoring of key areas, you can see the heap, non-heap memory, the memory pool status, frequency and duration of GC, GC can manually view the memory changes. As shown below:

Wherein the top of the figure can choose which of the changes in the memory (heap, non-heap, Old region, Eden region, Survivor region, metaspace area, etc.), may be performed manually GC view changes. A display size and the use of memory size, the number and the GC FIG time downward, while histogram shows the change manner of the stack and non-stack. Therefore, for a memory overflow, OOM these issues, see here is very suitable for monitoring data.

2.2.3 Thread

Online applications, mainly due to thread long pause are: wait for external resources (database connections, network resources, equipment resources, etc.), infinite loop, lock wait (live locks and deadlocks), which requires monitoring of java application thread operating conditions, as shown below:

The number of threads changes click on a thread and view the running state analysis, which can also click on the "Deadlock Detection" function to handle deadlock.

2.2.4 Class

This function is mainly used to view the total number of classes loaded, if the loaded class has been increasing, we have to see if the code is the code of the class continue to produce. As shown below:

2.2.5 VM Summary

When we add a startup parameter to java application ( JAVA_OPTS), if you want to see the actual usage of online application of this parameter is in effect, the command-line tools we use jinfo, where you can now see directly, but also the system information, class information, and information related to the VM heap parameters. As shown below:

3 jvisualvm use

And jconsolesimilar, jdk bin directory also provides the jvisualvmtools, relatively speaking, jvisualvmmore powerful, under the windows, from the command line ( jvisualvm.exe) or simply double-click jvisualvm.exeto start running. Interested readers can refer to the jvisualvmtools of official documents use :https://docs.oracle.com/javase/8/docs/technotes/guides/visualvm/index.html

3.1 two connections

With jconsolethe same, jvisualvmyou can monitor the local java process can also be monitored remotely java process. You can directly select a local process, remote process also need to add JMX java process startup parameters.

3.2 jvisualvm feature uses

jvisualvm more powerful features, including the following functions:

  • Display configuration of the virtual machine process and process environmental information (jps, jinfo).
  • Monitoring the application CPU, GC, heap, the method area (1.7 and earlier), element space (JDK1.8 and later) and thread information, the equivalent of jmap, jstat, jstack.
  • dump heap dump analysis and snapshot (jmap, jhat).
  • Running performance level method of analysis to identify the most calls, the longest running method.
  • Offline program Snapshot: running collection procedures when configuring the thread dump, dump memory, and other information to create a snapshot

The main function of the interface is divided into several modules, which are outlined, monitoring, thread, sampler.

3.2.1 Overview

Overview quite a java command-line tool jpsand jinfocan process and display configuration process, system properties, startup parameters, and jconsole"VM Summary" almost. As shown below:

3.2.2 monitoring

This function is equivalent to jconsolethe "Overview" function, the same is graphically display CPU, heap changes, changes in the number of threads and loading type of situation, but it has a feature that can remotely dump a heap dump snapshots (equivalent jmap -dump:file=./heap.hprof PID) will choose the storage location when the dump.

dump a heap snapshot, we can manually download the file down, and then use its "Load Snapshot" function to load jvisualvm(need to select the file type is "hprof" type when loaded), further analysis of heap memory. After loading, will include summary information, classes and memory for instance, the class can also double-click to see the specific number of instances, if you find a lot of the number of instances of certain classes, or how much memory is relatively high, it is possible to know the problem . As follows:

3.2.3 Thread

This is equivalent to the function jconsoleof the "thread" function, but more abundant, it is the operational status of each thread, run time is graphically displayed, but also can be remote thread dump, this feature, in fact, jstack -lfunction, dump after out directly to the display interface. as follows:

3.2.4 sampler

Sampling is a jvisualvmunique feature, you can sample display of CPU and memory, the memory information from time to time, thread information, you can easily concentrate on analyzing the data change certain period of time (it can be displayed in a hierarchical way down to the method execution time, memory for the class situation, etc.), also provides execute GC, memory dump and thread dump function. as follows:

4 Summary

With jconsoleand jvisualvmtwo visualization tools, you can reduce the input command line for easier, more intuitive way to monitor memory, threads, CPU and other information java applications, java online issue of dealing with a good helper. However, to note that it is, before you use these two tools, we still need a certain amount of accumulation of JVM, Java programs operating mechanism, thread and other knowledge. Hope this help.

Data sheet

Related Reading

Guess you like

Origin juejin.im/post/5d65490df265da03963ba917