Build JAVA diagnosis and collect data

1 Enable core file

         In the process of java running, java heap is generated, which will occupy a lot of disk space. Therefore, generally only when java crash occurs or when gdb debugs java native code, ulimit -c unlimited is enabled to diagnose errors.

2 Add -XX:+HeapDumpOnOutOfMemoryError to the JVM flags

       When a memory error occurs during java operation, check the cause of the memory error and enable this parameter. This parameter is the same as opening the core file. The java heap generated during the java operation will cause the file to be very large. By combining with the jhat tool, it can detect the memory occupied by objects and objects that fail to release memory correctly

3 Run a continuous Java flight recording

     Using java flight recorder, due to the commercial nature of java aircraft, free use is limited to desktop systems. If you want to use JFR in the production environment server, you need to purchase a license. If there is a problem with the operation of the java system, JFR records the situation in the last hour, Through these data analysis, the cause of the abnormality can be diagnosed. Such as: memory leak, high cpu load, thread blocking, etc.

4 Add -verbosegc to the JVM command-line

  Enable this parameter to collect Garbage-related information, such as how long the collector has been running and how long it has taken to release memory. According to these data, it is helpful to generate OutOFMemoryError原因.从jdk7开始,通过设置-Xloggc:<filename>   -XX:UseGCLogFileRotation and -XX: -NumberOfGCLogFiles=1 参数来输出到指定文件。

5 Print Java version and JVM flags

  Java runs the specific jvm version, in addition to using java -version to judge, you can also use parameters -XX+PrintCommandLineFlagsand-showversion检查版本

6Set up JMC JMX for remote monitoring

         By building jmc jmx, monitoring and diagnosing the remote java application is very practical. Generally, the application is deployed on the linux server, and it is necessary to diagnose the java running on the server. Directly use the jmx tool to monitor the vm or the command jcmd <pid> help ManagementAgent .start can achieve the purpose.

 

Summarize:

  core file [hs_err] : Find the cause of java application crash

      JFR : Use the flight recorder information to find the reason for the abnormal operation of the appliaction system.

  -XX:+HeapDumpOnOutOfMemoryError : Find memory leaks

      Exporting hprof can add parameters to specify the path -XX:HeapDumpPath=/path/to or /path/to/file

                                                   

  jcmd <pid> Thread.print/JFR : find slow/no response

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326402530&siteId=291194637