JAVA application monitoring

Java application detects content

  • When running a java application, it will generate a JVM instance, while the java application is running on this JVM instance, when an application exits, JVM instance will be shut down. Launch multiple java applications, will launch multiple JVM instances, they do not affect each other (of course, they will take up system resources).
  • There are three major virtual machine module, a class loader subsystem ( Class Loader Subsystemresponsible for loading classes), an execution engine ( Execution Engineresponsible for carrying out the method of instruction and class garbage collection), a run-time data area ( Runtime Data Areasdata storage program is responsible for run-time) .
  • Where runtime data divided into the method area (memory such as class information, method information, references, constant pool, etc.), the stack (storage class instance object and arrays), Java stack (in the stack mode is stored in units of frames stored threads running state frame), native method stacks (with associated local method of data area), the program counter (each thread has its own program counter indicates a command to be executed under the "address").
  • java application startup process is loaded by the loading associated Classes subsystem, and the data information such as classes, methods and the like stored in the stack area method, examples of related classes, and the instance of the object stored on the heap, running location is specified using a counter for each thread. Heap and method area is shared by the threads, the program counter and Java thread stack is private.
  • Run-time data area is the region java application run-time monitoring, in which case each region of memory, especially memory usage of the heap, are key areas. Heap will divide the young generation, old generation and the garbage collector will be generational recovery. Through its recovery monitoring, it can detect memory leaks, and java stack is related to threads, running state of the thread and associated with the CPU, so java stack monitoring may know the CPU utilization is too big a problem, but the method area and java stack size is also an indicator of memory for monitoring. Metaspace

How to monitor

Press monitoring tool monitoring methods, divided into the following four categories:

  • App - log and monitor page
  • java comes with command-line monitoring tools
  • java comes with visual monitoring tool
  • Third-party diagnostic tools

1 Built-monitoring program

Built-in monitoring procedure is relatively simple, beginner in java, the most common is to use the System.out.println()content you want the output to output, in the development stage it was also like this, one can export business content, the normal function of monitoring whether or not the other aspects may output system properties System.getProperties()and System.getProperty(). Of course, more usage log output frame, and outputs it to the log file by level, such as log4jand logback. For Spring Bootapplications, it can also be used actuatorto monitor the operation of the program. tomcatContainer itself with monitoring page. The main features of such monitoring program is built, and monitored by the log output, the developer is relatively familiar, in general, in the development and testing phase relatively common, but in a production environment, the log is generally errorlevel or because of security concerns, comes Some monitor pages is likely to shut down. Accordingly, such monitoring not elaborate.

2 java comes with command-line monitoring tools

Jdk bin directory under the installation directory, and already offers a variety of command-line monitoring tools to monitor java application developers and for operation and maintenance personnel, and facilitate the development and operation and maintenance personnel to diagnose the problem, therefore, these tools java application is an important means of monitoring. In general, common command-line tools include jps, jinfo, jmap, jstack, jstat, wherein

  • jpsView java process ID
  • jinfoCheck and adjust the parameters of the virtual machine
  • jmapView Heap (heap) and the use of raw heap snapshot
  • jstackView thread running state and generates a snapshot of the thread
  • jstatShow the process of class loading, operating data memory, garbage collection and so on.

With these tools, you can basically understand the change in the state memory java application thread running status and other information, and then provide the basis for application monitoring and problem diagnosis.

3 java comes with visual monitoring tool

In addition to command-line tool in the windows platform, jdk also provides visual monitoring tool, more intuitive, more convenient way to monitor the health of java applications. Both tools are jconsoleand jvisualvmcan be found in the bin directory of jdk. They can monitor local and remote java applications, including heap usage, threads, cpu use, class loading situation, gc circumstances, jvisualvmcan also generate the corresponding heap and thread snapshots, but also can use the corresponding plug-in in order to further analysis.

4 third-party diagnostic tools

In addition to java own tools, some third-party tools are also monitoring and diagnostic analysis, performance tuning tool, including MAT, BTraceand Arthas. among them

  • MATIt is eclipsea memory analysis plug-ins, by MATmay be made to dump the heap snapshot analysis, and assisted analysis memory leak causes, quickly compute the recovery operation of the occupied size of the object in memory, the garbage collector, and by statements intuitive see an object that may cause such results.
  • BTraceYes sun introduced a Java dynamic, secure tracking (monitoring) tool, you can monitor the operation of the system in case of non-stop, and do the least invasive, occupy minimal system resources. Especially suitable for monitoring of java application in a production environment, troubleshooting.
  • ArthasAli is a Java open source online diagnostic tool, can also include memory, the thread situation, GC, the runtime data in case of non-stop monitoring system can also monitor the method parameters, return values, exception return data, called artifacts, very easy to use in a production environment.


Guess you like

Origin www.cnblogs.com/doit8791/p/12081977.html