Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the application monitoring technology that java programmers should know

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces what the java programmer should know about the application monitoring technology, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1 introduction: why do you need to monitor java applications

Java developers know that java applications are launched with the java (class file) or java-jar (jar or war package) commands. The java command actually starts a java virtual machine (JVM), the program runs on JVM, JVM is responsible for class loading, runtime area stack allocation and other work, and the stack is used for the use of objects and threads in the program, respectively, affecting the cpu and memory of the system, if the program involves files or data reading and writing, it will also affect the IO of the system. Therefore, after a java app is launched, if it does not monitor the resources it consumes, there is no doubt that a plane takes off without a dashboard, and no one dares to take such a plane. Therefore, as a developer, it is necessary to be clear about the operation of the application after startup, and be able to monitor the operation of the application, so that we can predict the problems that may occur in time and correct them in time or faster after the problems occur. Better find the cause, and then solve it. Fortunately, the program itself, java tools and third-party tools all provide us with many ways to monitor java applications. Therefore, as java developers, it is necessary to have a systematic understanding of them in order to deal with problems more calmly and efficiently in practical applications (especially in production environments).

2 what to monitor

When a java application runs, if something goes wrong, our first reaction must be to check the log to see what is wrong. If there is no error, it is just slow, or it is just not reported yet, then what do we need to monitor? In this section, compared to the operating system we usually use, let's take a look at what needs to be monitored for java applications.

2.1 system Monitoring content

For the operating system we usually use, such as the windows,linux system, the application opens slowly and the system response is slow. Generally, it is necessary to check the cpu operation and memory usage of the system first, find out the process that takes up high resources, locate the reason, and view it directly in Task Manager-> performance in windows, as shown below.

In linux, you can view it using commands such as top,free,df,iostat, as shown in the following figure.

In the daily process of operation and maintenance, it is also to monitor the disk usage, IO, CPU, memory, network and other conditions of the system, and strive to find the processes that occupy high resources in time, locate the problems and then deal with them.

2.2 java application monitoring content

Compared with the operating system, java applications need to monitor similar content, such as the occupied cpu, memory, which will include java application JVM parameters, heap usage, thread running status, class loading, garbage collection (GC). As for why we need to monitor these contents, we need to have a certain understanding of the virtual machine (JVM) of java. As there are many contents involved in this JVM, we will have the opportunity to explain JVM in detail later. Here, we can make a brief introduction to the JVM system of java, so that readers can understand the following chapters. See the following figure:

When java runs an application, an instance of JVM is generated, and the java application runs in the JVM instance, and when the application exits, the JVM instance is closed. Launching multiple java applications also starts multiple JVM instances, which do not affect each other (of course, they all take up system resources).

The virtual machine mainly has three modules, a class loading subsystem (Class Loader Subsystem, responsible for loading classes), an execution engine (Execution Engine, responsible for executing class method instructions and garbage collection), and a runtime data area (Runtime Data Areas, which is responsible for storing data when the program is running).

The runtime data is divided into method areas (storing class information, method information, references, constant pools, etc.), heaps (storing class instance objects and arrays), java stacks (storing threads' running state frames in frames), local method stacks (data areas associated with local methods), and program counters (each thread has its own program counter. Represents the "address" of the next instruction to be executed.

The java application startup process is to load the relevant classes through the class loading subsystem, then store the relevant data such as class information and methods in the stack of the method area, instantiate the relevant classes, and store the instance objects in the heap at the same time, and the program running location is specified by each thread using the counter. The method area and heap are shared by threads, and program counters and Java stacks are thread-private.

The runtime data area is the monitoring area when the java application is running, in which the memory situation of each area, especially the memory usage of the heap, is the key area. The heap will also be divided into the young generation, the old generation and the Metaspace, and the garbage collector will recycle it from generation to generation. Through its recycling monitoring, we can detect whether there is a memory leak, while the java stack is related to the thread, and the running state of the thread is related to CPU, so the monitoring of the java stack can know the problem that the CPU occupies too much. At the same time, the memory occupied by the method area and java stack is also a monitoring index.

3 how to monitor

From the above description, we probably already know why we need to monitor java applications and what we need to monitor after a java application is launched. Then how to monitor it when it is put into practical application? The following is an overview of java application monitoring tools and methods, followed by a series of articles in the form of a detailed introduction of various monitoring tools and methods.

According to the monitoring methods of monitoring tools, they are mainly divided into the following four categories:

Built-in program-log and monitoring page

Java comes with command line monitoring tools

Java comes with visual monitoring tools.

Third-party diagnostic tool

3.1 Program built-in monitoring

Program built-in monitoring is relatively simple, when learning java, the most commonly used is to use System.out.println () to output the content they want to output, in the development stage, some people like this, on the one hand, you can output business content, monitoring function is normal or not, on the other hand, you can output system attributes System.getProperties () and System.getProperty (). Of course, it is now more common to use the logging framework for output, and output logs to files by level, such as log4j and logback. For Spring Boot applications, you can also use actuator to monitor the running of the program. The tomcat container itself also comes with a monitoring page. The main feature of this kind of monitoring is that the program is built in, and it is monitored through log output, which developers are relatively familiar with, and are generally used in the development and testing phase, while in production environments, logs are generally at error level or some monitoring pages that come with them may be closed due to security considerations. Therefore, such monitoring is no longer detailed.

3.2 java comes with command line monitoring tools

The bin directory under the installation directory of jdk has provided a variety of command line monitoring tools to facilitate developers and operators to monitor java applications and to facilitate developers and operators to diagnose problems. Therefore, such tools are an important means of java application monitoring. Generally speaking, common command-line tools include jps,jinfo,jmap,jstack,jstat, where

Jps View java process ID

Jinfo views and adjusts virtual machine parameters

Jmap view heap (heap) usage and generate heap snapshots

Jstack to check thread running status and generate thread snapshot

Jstat displays class loading, memory, garbage collection and other running data in the process.

Through these tools, we can basically understand the memory change state, thread running state and other information of java applications, and then provide a basis for application monitoring and problem diagnosis. These tools will be described in detail in later articles.

3.3 java comes with visual monitoring tools

In addition to command-line tools, under the windows platform, jdk also provides visual monitoring tools to monitor the running status of java applications in a more intuitive and convenient way. The two tools, jconsole and jvisualvm, can be found in the bin directory under jdk. They can monitor local and remote java applications, including heap usage, thread usage, cpu usage, class loading, gc, jvisualvm can also generate corresponding heap and thread snapshots, and can also use corresponding plug-ins for further analysis. The use of these two tools will be described in detail in a later article.

3.4 third-party diagnostic tools

In addition to java's own tools, some third-party tools are also powerful tools for monitoring, analysis, diagnosis and performance tuning, including MAT,BTrace and Arthas. Among them

MAT is the memory analysis plug-in of eclipse. Through MAT, you can analyze the heap snapshot of dump, analyze the cause of memory leak, quickly calculate the occupancy of objects in memory, the collection work of garbage collector, and directly view the objects that may cause this result through the report.

BTrace is a Java dynamic and security tracking (monitoring) tool launched by sun, which can monitor the operation of the system without downtime, and achieve the least intrusion and occupy the least system resources. It is especially suitable for monitoring and troubleshooting java applications in the production environment.

Arthas is an open source online Java diagnostic tool from Ali, which can also monitor the system without downtime, including memory, thread, GC, runtime data, as well as method parameters, return values, exception returns and other data. It can be called an artifact and is very convenient to use in a production environment.

About java programmers should know what the application monitoring technology is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report