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

The principle of Agent injection Mechanism of UAV MOF working principle

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

I. Preface

As a UAV application data capture framework, MOF (Moniter Framwork) not only realizes the non-invasive data capture of the application, but also realizes the flexible control of the function at the framework level, and ensures good scalability, so it plays an important role in UAV.

As the basis of UAV MOF work, MOF Agent injection mechanism also provides the possibility for UAV to capture application data without intrusion. UAV Agent code injection mechanism combines javaagent (premain) and javaassist technology to rewrite bytecode before applying bytecode to JVM. Adapting (adaptor) to different application servers, including Tomcat (6 +), SpringBoot, Jetty (7 +), etc., combined with interceptor (interceptor) to realize the pointcut of different application servers, providing the basis for MOF framework and application data capture.

II. Java Agent technology

Since JDK1.5, the java.lang.Instrument package has been introduced into JDK, which provides the ability to modify class bytecode before the Java program class is loaded and dynamically modify the Class type in the system at run time. One of the core concepts, Java Agent, can be understood as a bytecode converter or Class object converter. For bytecode conversion and Class object conversion, Java agent provides the corresponding methods, namely Java agent premain mode and Java agent agentmain mode. UAV MOF uses the Java agent premain method, so this article focuses on this transformation.

Java agent premain provides the magical ability to intercept and modify bytecode class files before they are loaded by JVM. At present, almost all probe-based monitoring systems (such as ONEAPM Servers) are based on this ability to achieve non-intrusive monitoring of applications. There are two important concepts in Java agent premain, premain and transformer.

Premain will be executed before the program's main method, and we know that the entry to the program is the main method, and premain represents the action performed before the program is officially started, with AOP-like capabilities. Transformer, the implied converter, provides the ability to convert bytecode file streams.

Fig. 1 conversion diagram of Class file

Collection of premain and transformer two artifacts, can be loaded into the JVM of any Class file can be modified. The process is shown in figure 1. When any Class file is loaded, it goes through the premain level, and eventually becomes the perfect one through a series of transformer,Class bytecode file streams, which is then loaded into JVM. Of course, the modification of the Class bytecode file stream is done in transformer. This is a problem, get the bytecode file stream, how to modify it? Of course, to give full play to human strengths, with the help of tools, such as javassist.

III. Javassist technology

Javaassist is an open source library for analyzing, editing, and creating Java bytecode, which can dynamically generate classes, modify classes, and directly use java coding at run time.

In the previous Java agent technology, we get the bytecode file stream of the class in transformer, and use Javaassist to parse the byte code stream into the class object, and modify it, which is very fast and convenient. The combination of Javassist and Java agent will get twice the result with half the effort. For more information about the use of Javaassist, please refer to the official website http://www.javassist.org.

4. MOF Agent injection mechanism

In the previous article, we introduced a pair of good partners: Javaagent technology and Javassit technology. Java agent is responsible for intercepting and converting byte streams, which are parsed and modified by Javaassist during the conversion process. These two technologies provide a technical basis for MOF Agent injection mechanism. I believe that the partner already has a certain conjecture about the MOF Agent injection mechanism.

Figure 2 shows the component diagram of MOFAgent. MOFAgent is implemented based on java agent premain technology, intercepts all loaded Class bytecode file streams, and hijacks and converts bytecodes through UAV's transformer (MOFClsTransformer). UAV does not only that, but also automatically perceives different application servers and injects pointcuts into important locations in the lifecycle of different application servers. UAV adapts different application services through adapter (Adaptor) and implements specific pointcut injection through interceptor (interceptor).

Figure 2 MOF Agent component diagram

The MOFAgent injection mechanism will inject pointcuts into the key locations in the life cycle of the application server, providing the basis for MOF framework initialization, application portrait information and real-time monitoring data information capture. Different pointcuts of MOF Agent injection will produce different events, which drive the subsequent MOF framework through events. The main pointcuts supported by MOF are as follows:

1) Application Server Portal

Application server entry pointcut, UAV will complete MOF Jar package loading and configuration file initialization

2) start the application server

When the application server starts, it will guarantee that UAV MOF will complete the self-startup and initialization of the MOF internal code with the application server startup.

3) Application server request processing and reply

Application server request and reply pointcut is an important pointcut for UAV to capture application real-time monitoring data, and to monitor the performance indicators of application servers, applications, and all URL

4) Application initialization

When the application initializes the pointcut, UAV will rewrite the Filter of the application, support the Global Filter mechanism of MOF, and capture the application portrait information.

5) stop the application

When the application stops, UAV will complete the operations such as stopping the MOF mechanism.

The main purpose of this article is to let readers understand the principle and related implementation of UAV MOF Agent code injection mechanism. Other important frameworks in MOF and their implementation principles will be analyzed in turn in the following articles.

Author: Zeng Li

First: UAVStack Intelligent Operation and maintenance

Source: Yixin Institute of Technology

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

Network Security

Wechat

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

12
Report