CN117112341A - Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation - Google Patents

Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation Download PDF

Info

Publication number
CN117112341A
CN117112341A CN202310902308.4A CN202310902308A CN117112341A CN 117112341 A CN117112341 A CN 117112341A CN 202310902308 A CN202310902308 A CN 202310902308A CN 117112341 A CN117112341 A CN 117112341A
Authority
CN
China
Prior art keywords
java
key information
monitored
class
asm
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310902308.4A
Other languages
Chinese (zh)
Inventor
张皓
王志刚
刘振宇
白雪珂
乔振浩
王晶
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Aisino Corp
Original Assignee
Aisino Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Aisino Corp filed Critical Aisino Corp
Priority to CN202310902308.4A priority Critical patent/CN117112341A/en
Publication of CN117112341A publication Critical patent/CN117112341A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3006Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is distributed, e.g. networked systems, clusters, multiprocessor systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3055Monitoring arrangements for monitoring the status of the computing system or of the computing system component, e.g. monitoring if the computing system is on, off, available, not available
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/32Monitoring with visual or acoustical indication of the functioning of the machine
    • G06F11/324Display of status information
    • G06F11/328Computer systems status display
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/26Visual data mining; Browsing structured data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9538Presentation of query results
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/04Processing captured monitoring data, e.g. for logfile generation
    • H04L43/045Processing captured monitoring data, e.g. for logfile generation for graphical visualisation of monitoring data
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters

Abstract

The invention discloses a non-invasive quasi-real-time monitoring method and a system based on ASM byte code instrumentation, wherein the method comprises the following steps: key information in the execution process of the monitored Java method is collected in a non-invasive mode through a Java technology and an ASM framework, and the collected key information is transmitted to a message queue realized on the basis of a RocketMQ; the key information is sent to a monitoring service platform back-end program through a message queue realized based on the RocketMQ; the key information of the message queue is consumed and subjected to lasting treatment through a monitoring service platform back-end program, and is stored into an RDBMS relational database; obtaining key information from the RDBMS relational database by using an elastic search engine for quasi-real-time searching and analysis; and displaying the analysis result to a front-end page of the monitoring service platform through the ECharts visualization tool.

Description

Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation
Technical Field
The invention relates to the technical field of information monitoring, in particular to a non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation.
Background
The currently mainstream architecture of the software system includes an important component: monitoring the service. The system can collect, calculate, analyze and visually display the running condition of each system service in real time, and the content comprises monitoring information such as QPS (query rate per second), TPS (transaction rate per second), health degree, availability, response time length, call volume, load, CPU (central processing unit) and the like. A set of perfect monitoring service not only can ensure the normal operation of a software system, but also can provide powerful support for operation and maintenance personnel and operation personnel.
Early monitoring services typically required the injection of specific monitoring codes into the business code in a hard-coded manner in a software system to implement the corresponding monitoring functions. This approach can lead to a large intrusion of monitoring codes into the business system, which both damages the code structure of the original architectural design and severely affects the stability of the system. Meanwhile, since the monitoring codes are generally scattered and trivial, if the existing monitoring functions are required to be expanded or migrated to other systems, the cost is quite high, and even if the function expansion or the migration of the monitoring capability is completed, the follow-up maintenance is still difficult.
Disclosure of Invention
In order to solve at least one of the problems described in the background art, the present invention provides a non-invasive quasi-real-time monitoring method and system based on ASM bytecode instrumentation.
According to one aspect of the present invention, there is provided a non-invasive quasi-real-time monitoring method based on ASM bytecode instrumentation, comprising:
key information in the execution process of the monitored Java method is collected in a non-invasive mode through a Java technology and an ASM framework, and the collected key information is transmitted to a message queue realized on the basis of a RocketMQ;
the key information is sent to a monitoring service platform back-end program through a message queue realized based on the RocketMQ;
the key information of the message queue is consumed and subjected to lasting treatment through a monitoring service platform back-end program, and is stored into an RDBMS relational database;
obtaining key information from the RDBMS relational database by using an elastic search engine for quasi-real-time searching and analysis;
and displaying the analysis result to a front-end page of the monitoring service platform through the ECharts visualization tool.
Optionally, the collecting key information in the monitored Java method execution process in a non-invasive manner through the Java agent technology and the ASM framework includes:
the entry function of the JavaAgents program is realized through the JavaAgentMain class;
realizing the operation logic of the byte code by using an ASM framework through a ByteCode converter class;
analyzing the information of the Java method in a byte code mode through a ByteCode method tester class;
entering a monitored Java method and enhancing byte codes;
and when the logic execution of the monitored Java method is finished, ending the Java method and enhancing the byte code to obtain the monitored key information when the Java method is executed.
Optionally, the implementation of the entry function of the java agent program through the java agent main class includes:
when the Java program runs, the Java virtual machine calls a premain method with a String type entry and an Instrumentation type entry on the Java AgentMain class;
if the JavaAgentMain class does not realize a premain method with String type entry and Instrumentation type entry, the Java virtual machine calls the premain method only comprising String type entry;
the path information of the Java AgentMain class is configured into a MANIFEST.MF file, wherein the MANIFEST.MF file is used for defining extension or archive package related data in a Java program.
Optionally, the operation logic for implementing the byte code by using the ASM framework through the bytecode convertensformer class includes:
the bytecode converter class implements the operation logic of the bytecode with the class ClassReader, classWriter and classinitiator provided within the ASM framework.
Optionally, the parsing the information of the Java method in a bytecode manner through the bytecode method identifier class includes:
in the process of loading and starting Java programs, monitoring all Java methods of all classes, and acquiring names, method names, entry types, entry values, return types and method return values of all the classes, wherein the entry types, the entry values, the return types and the method return values are described as a section of fixed character string by an ASM framework;
according to the description of the ASM framework official document on the fixed character string, analyzing the character strings of the parameter entering type, the parameter entering value, the return type and the method return value by using a regular expression;
and generating a globally unique identification ID of the monitored Java method by utilizing the analyzed method information.
Optionally, the entering the monitored Java method and enhancing the bytecode includes:
by overwriting the onmethod enter method in the sub-class ByteCode method Viactor inheriting the parent class AdviceAdapter, it is used to set the start time when entering the Java method being monitored;
using byte codes to pile the logic with the set start time to the start of the monitored Java method when entering;
creating and initializing an object type array with the same capacity as the monitored Java method parameter by using byte codes;
all the entry information of the monitored Java method is added into the created object type array through byte codes.
Optionally, when the logic execution of the monitored Java method is finished, ending the Java method and enhancing the byte code to obtain the monitored key information when the Java method is executed, including:
when the monitored Java method logic is executed, ending the Java method, and determining that the method is time-consuming to execute;
the method of rewriting onmethod exit uses byte code to obtain class name, method name, entry type, entry parameter value, return type, method return value and method execution time consuming and output to outside as key information monitored when Java method is executed.
According to yet another aspect of the present invention, there is provided a non-invasive quasi-real-time monitoring system based on ASM bytecode instrumentation, comprising:
the key information acquisition and transmission module is used for acquiring key information in the execution process of the monitored Java method in a non-invasive mode through a Java technology and an ASM framework, and transmitting the acquired key information to a message queue realized on the basis of the RocketMQ;
the key information sending module is used for sending the key information to a monitoring service platform back-end program through a message queue realized based on the RocketMQ;
the key information storage module is used for carrying out consumption and persistence processing on key information of the message queue through a monitoring service platform back-end program and storing the key information into the RDBMS relational database;
the key information analysis module is used for acquiring key information from the RDBMS relational database by utilizing the elastic search engine to perform quasi-real-time search and analysis;
and the visual display module is used for displaying the analysis result to a front-end page of the monitoring service platform through the ECharts visual tool.
According to a further aspect of the present invention there is provided a computer readable storage medium storing a computer program for performing the method according to any one of the above aspects of the present invention.
According to still another aspect of the present invention, there is provided an electronic device including: a processor; a memory for storing the processor-executable instructions; the processor is configured to read the executable instructions from the memory and execute the instructions to implement the method according to any of the above aspects of the present invention.
The invention uses Java technology to combine ASM frame to realize byte code enhancement to the monitored Java method, to collect and transmit key information such as class name, method name, parameter type, parameter value, return type, return value and time consumption of method execution in the method execution process in non-invasive mode, thereby completing full-link monitoring of Java program and verifying Java engineering code quality with quantized data. After the key information of the Java program is collected, the key information is directly pressed into a message queue realized based on RocketMQ, the consumption of the queue information is carried out by a monitoring service platform, the queue information is finally stored in a relational database RDBMS in a lasting mode, meanwhile, quasi-real-time monitoring information searching and analysis are realized by utilizing an elastic search, and the analysis result is visually displayed based on ECharts through a front-end page of the monitoring service platform, so that quasi-real-time, high-availability and high-performance monitoring data analysis display is realized.
Drawings
Exemplary embodiments of the present invention may be more completely understood in consideration of the following drawings:
FIG. 1 is a flow chart of a non-invasive quasi-real-time monitoring method based on ASM bytecode instrumentation according to an exemplary embodiment of the present invention;
FIG. 2 is a flow chart of a bytecode instrumentation scheme provided by an exemplary embodiment of the present invention;
FIG. 3 is an example of a bytecode instrumentation effect provided by an exemplary embodiment of the present invention;
FIG. 4 is a diagram of an overall architecture of a bytecode instrumentation provided by an exemplary embodiment of the present invention;
FIG. 5 is a schematic diagram of a non-invasive quasi-real-time monitoring system based on ASM bytecode instrumentation according to an exemplary embodiment of the present invention;
fig. 6 is a structure of an electronic device provided in an exemplary embodiment of the present invention.
Detailed Description
Hereinafter, exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. It should be apparent that the described embodiments are only some embodiments of the present invention and not all embodiments of the present invention, and it should be understood that the present invention is not limited by the example embodiments described herein.
It should be noted that: the relative arrangement of the components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless it is specifically stated otherwise.
Fig. 1 shows a flow chart of a non-invasive quasi-real-time monitoring method based on ASM bytecode instrumentation provided by the present invention. As shown in fig. 1, the non-invasive quasi-real-time monitoring method based on ASM bytecode instrumentation includes:
step S10: key information in the execution process of the monitored Java method is collected in a non-invasive mode through a Java technology and an ASM framework, and the collected key information is transmitted to a message queue realized on the basis of a RocketMQ;
in the embodiment of the invention, as shown in a byte code instrumentation scheme flow chart in fig. 2, in order to realize unified non-invasive monitoring service, the invention proposes to complete enhancement processing on a monitored program method in a byte code instrumentation mode during code loading, collect necessary information required by monitoring and send the necessary information to a monitoring service platform rear-end program through a RocketMQ (a distributed message middleware with low delay, high concurrency, high availability and high reliability) message queue on the premise of not influencing original program logic, and perform quasi-real-time search and analysis by matching with an elastic search (a distributed search and analysis engine with open source), and display the result to a monitoring service platform front-end page through a visualization tool ECharts (an open source data visualization chart library), thereby helping a user to quickly and intuitively observe state information of each system service during operation and providing a complete set of high-availability, high-performance, quasi-real-time and visual monitoring service platform scheme.
The invention provides a non-invasive quasi-real-time monitoring system and method based on ASM (Java byte code control framework) byte code instrumentation, which utilizes the ASM byte code framework to realize enhancement processing on the byte codes of program codes and completes information acquisition on the execution condition of the code method when the program runs. As in the example of the bytecode instrumentation effect of fig. 3.
Specifically, the method for capturing information during execution of the Java method through the Java technology and the ASM framework specifically comprises the following steps: class name, method name, type of entry, value of entry, type of return, value of return, and time consuming execution of the method. The Java agent is a probe technology, and performs byte code enhancement on a specified method in the class loading process through a premain method. The Java class is converted into the byte code instruction and then executed, so that the method enhanced by the Java probe technology can be used for outputting the required monitoring information according to the requirements at will, and the same effect as the invasive hard-coded monitoring code with obvious defects is achieved. ASM is a Java bytecode processing framework with the ability to dynamically generate classes or enhance existing classes. ASM can directly generate binary class files (a binary file that can run on any hardware platform and operating system that supports Java virtual machines) and support dynamically changing the behavior of classes before they are loaded into Java virtual machines. Since Java class compilations are stored in strictly format defined class suffix files, these class files possess sophisticated metadata that can be used to parse elements in the class, such as class names, methods, attributes, and Java bytecode instructions. Therefore, after the ASM reads the information from the class suffix file, the ASM can change the behavior of the class, analyze the information of the class, and generate a new class according to the service requirement. That is, ASM achieves the purpose of modifying class files by directly modifying bytecodes.
Optionally, the collecting key information in the monitored Java method execution process in a non-invasive manner through the Java agent technology and the ASM framework includes: the entry function of the JavaAgents program is realized through the JavaAgentMain class; realizing the operation logic of the byte code by using an ASM framework through a ByteCode converter class; analyzing the information of the Java method in a byte code mode through a ByteCode method tester class; entering a monitored Java method and enhancing byte codes; and when the logic execution of the monitored Java method is finished, ending the Java method and enhancing the byte code to obtain the monitored key information when the Java method is executed.
Optionally, the implementation of the entry function of the java agent program through the java agent main class includes: when the Java program runs, the Java virtual machine calls a premain method with a String type entry and an Instrumentation type entry on the Java AgentMain class; if the JavaAgentMain class does not realize a premain method with String type entry and Instrumentation type entry, the Java virtual machine calls the premain method only comprising String type entry; the path information of the Java AgentMain class is configured into a MANIFEST.MF file, wherein the MANIFEST.MF file is used for defining extension or archive package related data in a Java program.
In the embodiment of the invention, the entry function of the Java agent program is realized through the Java AgentMain class, which is an entry method class with fixed Java agent technology, and all the Java agent programs start from the entry method class. The specific logic is as follows: when the Java program runs, the Java virtual machine firstly tries to call a premain method with String type entries and Instrumentation type entries on the Java AgentMain class, and if the Java AgentMain class does not realize the premain method with the String type entries, the Java virtual machine tries to call the premain method only comprising String type entries. In addition, path information of the JavaAgentMain class needs to be configured into a manifest. Mf file (used in Java to define extension or archive package related data).
Optionally, the operation logic for implementing the byte code by using the ASM framework through the bytecode convertensformer class includes: the bytecode converter class implements the operation logic of the bytecode with the class ClassReader, classWriter and classinitiator provided within the ASM framework.
In the embodiment of the invention, the byte code is processed by the ByteCode converter class, and the information such as class loader, class name, byte code and the like of the class needing to be monitored is transmitted into the ByteCode converter class, so that the enhancement operation of the byte code is performed. Such would utilize an ASM framework for byte code processing, primarily using the class of operations ClassReader, classWriter and classvisator provided within the framework to implement processing logic.
Optionally, the parsing the information of the Java method in a bytecode manner through the bytecode method identifier class includes: in the process of loading and starting Java programs, monitoring all Java methods of all classes, and acquiring names, method names, entry types, entry values, return types and method return values of all the classes, wherein the entry types, the entry values, the return types and the method return values are described as a section of fixed character string by an ASM framework; according to the description of the ASM framework official document on the fixed character string, analyzing the character strings of the parameter entering type, the parameter entering value, the return type and the method return value by using a regular expression; and generating a globally unique identification ID of the monitored Java method by utilizing the analyzed method information.
In the embodiment of the invention, the analysis of the Java method is realized by the ByteCode method viewer class in the form of byte codes, all methods of all classes can be monitored in the process of loading and starting the Java program, and the information such as the class name, the method parameter entry, the method return value and the like can be obtained at the stage. In order to avoid the problem of resource waste caused by repeated transmission of the monitored method acquired by each processing position of the subsequent monitoring logic, the logic designed here is to generate a global unique ID for each method, and the monitoring logic can be directly positioned to the corresponding method through the ID when being processed so as to improve the performance. Because the entering information and the returning information of the monitored method can be described as a section of fixed character string by the ASM framework, the character string needs to be disassembled and matched in order to facilitate the analysis of the entering information and the returning information. The specific logic is as follows: according to the description of ASM official documents on the fixed character strings, the regular expression is utilized to disassemble and match the character strings of the input parameter and the return value, the input parameter type and the return type are obtained first, then the specific values stored in the input parameter information and the return information are processed, 8 basic types of Java are converted into Java objects through type conversion and are filled into an array which can only store the object types, and the Java objects are used for outputting the subsequent results. Next, the globally unique ID of the method is generated using the method information analyzed previously, such as the entry information, the return information, etc., to ensure that each method has one such ID. It should be noted that, for such an atomicity self-increment ID, a definition may be made by using an atom type of Java (an interger class supporting atomic operations), and a collection of atom reference array types may be further defined, and then, each time a method is added, a corresponding ID is generated by using this logic and returned, and then, stored in the collection. Because the generation of all IDs is completed at one time, the time consumption of the execution when the monitoring information is collected is not influenced.
Optionally, the entering the monitored Java method and enhancing the bytecode includes: by overwriting the onmethod enter method in the sub-class ByteCode method Viactor inheriting the parent class AdviceAdapter, it is used to set the start time when entering the Java method being monitored; using byte codes to pile the logic with the set start time to the start of the monitored Java method when entering; creating and initializing an object type array with the same capacity as the monitored Java method parameter by using byte codes; all the entry information of the monitored Java method is added into the created object type array through byte codes.
In the embodiment of the invention, a link of entering a monitored Java method and enhancing byte codes is needed. By overwriting the onmethod enter method in the sub-class ByteCode method Viactor inheriting the parent class AdviceAdapter, it is used to set the start time when entering the method and collect the entry parameter information into the array. The core logic is to use byte codes to create an array, then to add all the parameter information of the method to the array through the byte codes, which is equivalent to the process of defining the array and then setting parameters when writing Java codes. The specific principle is as follows: firstly, using byte codes to pile logic of 'set start time' to the start position of the method when the method is entered, then using byte codes to create and initialize an object type array with the same capacity as the parameter quantity of the method, and finally still performing addition assignment of parameter entering information on the array through the byte codes. The process of assigning includes an act of converting the Java base type to an object type, because only the object type is allowed to be deposited into an array of object types, and none of the Java base types are object types. The specific bytecode instructions used by this link with the ASM framework include: LS TORE, BIPUSH, ANEWARRAY, ILOAD, INVOKESTATIC and AASTOR E, etc. Wherein LSTORE is responsible for saving the stack top long type value into the local variable index byte; BI PUSH is responsible for the signed expansion of value byte values into int values to be stacked; ANEWARRAY is responsible for creating an array of reference types; ILOAD is responsible for loading int-type values from the local variable index byte to be stacked; the IN VOKESTATIC is responsible for invoking the static method; AASTORE is responsible for saving the top of stack reference type value to the specified entry specifying the reference type array. The parameter information is added to the array for subsequent output to the outside.
Optionally, when the logic execution of the monitored Java method is finished, ending the Java method and enhancing the byte code to obtain the monitored key information when the Java method is executed, including: when the monitored Java method logic is executed, ending the Java method, and determining that the method is time-consuming to execute; the method of rewriting onmethod exit uses byte code to obtain class name, method name, entry type, entry parameter value, return type, method return value and method execution time consuming and output to outside as key information monitored when Java method is executed.
In the embodiment of the invention, when the monitored Java method logic is executed, the link of ending the Java method and enhancing the byte code is reached, and the core logic obtains the return information by using the byte code and outputs the return information to the outside through the rewriting onmethod exit method. The specific bytecode instructions used by this link with the ASM framework include: LLOAD, LDC, ALOAD, INVOKESTATIC, etc. The LLOAD is responsible for loading a long type value from a local variable index byte to be stacked, and the monitoring logic corresponding to the method is the starting time of a loading method; the LDC is responsible for pushing the constant value stored in the constant pool to a stack, and the monitoring logic corresponding to the invention is the unique ID of the loading method; ALOAD is matched with the content mark of the parameter entering information, and is responsible for loading the reference type value from the local variable index byte to be stacked, and the monitoring logic corresponding to the invention loads the array with the parameter entering information; ALOAD matches the content mark of the return information, and the loading is the method return information; the INVOKESTATIC is responsible for calling the static method to output result information. Thus, the method has the capability of outputting monitoring information such as class names, method names, parameter entering types, parameter entering values, return types, return values, time consumption of method execution and the like by acquiring the method IDs.
Step S20: the key information is sent to a monitoring service platform back-end program through a message queue realized based on the RocketMQ;
step S30: the key information of the message queue is consumed and subjected to lasting treatment through a monitoring service platform back-end program, and is stored into an RDBMS relational database;
step S40: obtaining key information from the RDBMS relational database by using an elastic search engine for quasi-real-time searching and analysis;
step S50: and displaying the analysis result to a front-end page of the monitoring service platform through the ECharts visualization tool.
In the embodiment of the invention, as shown in fig. 4, a whole structure diagram of the byte code instrumentation is shown, java monitoring codes are compiled and packaged into a jar suffix type file, java parameters are added when a Java program to be monitored is started, jar type files of the monitoring codes are specified, the implementation method enhancement of the byte code instrumentation can be carried out on the Java program to be monitored, monitored information during execution is output to a message queue based on the RocketMQ implementation, then a rear-end program of a monitoring service platform carries out consumption and persistence processing on data of the message queue, the data are stored in an elastic search and an RDBMS (relational database), quasi-real-time searching and analysis are carried out on the obtained monitoring information, the result is displayed on a front-end page of the monitoring service platform, and the implementation of the whole monitoring process is completed rapidly and conveniently.
The invention realizes collection and transmission of Java program monitoring information in a non-invasive manner by inserting byte codes, can greatly ensure independence, expansibility and stability between a monitored system and monitoring codes, ensures that the monitoring codes have very flexible migration capability, and supports quick access to any application system developed by Java technology. The bytecode instrumentation implemented based on ASM framework is also excellent in performance, while technologies such as Javassist, byte-buddy have the capability of manipulating bytecodes in addition to ASM and are even simpler in technical implementation than ASM, they are less efficient to execute than ASM, the most important of which is that ASM framework directly uses instructions to control bytecodes. Meanwhile, the monitoring information collected in the Java program running process is directly pressed into a RocketMQ message queue with excellent performance, searching and analysis are completed by utilizing an elastic search distributed cluster, and quasi-real-time, high-availability and high-performance monitoring data analysis and display can be easily realized by matching with ECharts visualization tools.
Exemplary System
Fig. 5 is a schematic structural diagram of a non-invasive quasi-real-time monitoring system based on ASM bytecode instrumentation according to an exemplary embodiment of the present invention. As shown in fig. 5, the system 500 includes:
the key information acquisition and transmission module 510 is configured to acquire key information in the execution process of the monitored Java method in a non-invasive manner through a Java agent technology and an ASM framework, and transmit the acquired key information to a message queue implemented based on a rock mq;
the key information sending module 520 is configured to send key information to a monitoring service platform back-end program through a message queue implemented based on a dockmq;
the key information storage module 530 is configured to perform consumption and persistence processing on key information of the message queue through a monitoring service platform back-end program, and store the key information in the RDBMS relational database;
the key information analysis module 540 is used for acquiring key information from the RDBMS relational database by using the elastic search engine for quasi-real-time searching and analysis;
and the visual display module 550 is used for displaying the analysis result to the front-end page of the monitoring service platform through the ECharts visual tool.
The non-invasive quasi-real-time monitoring system based on ASM bytecode instrumentation of the embodiment of the present invention corresponds to the non-invasive quasi-real-time monitoring method based on ASM bytecode instrumentation of another embodiment of the present invention, and is not described herein.
Exemplary electronic device
Fig. 6 is a structure of an electronic device provided in an exemplary embodiment of the present invention. As shown in fig. 6, the electronic device 60 includes one or more processors 61 and memory 62.
The processor 61 may be a Central Processing Unit (CPU) or other form of processing unit having data processing and/or instruction execution capabilities and may control other components in the electronic device to perform the desired functions.
Memory 62 may include one or more computer program products that may include various forms of computer-readable storage media, such as volatile memory and/or non-volatile memory. The volatile memory may include, for example, random Access Memory (RAM) and/or cache memory (cache), and the like. The non-volatile memory may include, for example, read Only Memory (ROM), hard disk, flash memory, and the like. One or more computer program instructions may be stored on the computer readable storage medium that can be executed by the processor 61 to implement the method of information mining historical change records and/or other desired functions of the software program of the various embodiments of the present invention described above. In one example, the electronic device may further include: an input device 63 and an output device 64, which are interconnected by a bus system and/or other forms of connection mechanisms (not shown).
In addition, the input device 63 may also include, for example, a keyboard, a mouse, and the like.
The output device 64 can output various information to the outside. The output means 64 may include, for example, a display, speakers, a printer, and a communication network and remote output devices connected thereto, etc.
Of course, only some of the components of the electronic device that are relevant to the present invention are shown in fig. 6 for simplicity, components such as buses, input/output interfaces, etc. being omitted. In addition, the electronic device may include any other suitable components depending on the particular application.
Exemplary computer program product and computer readable storage Medium
In addition to the methods and apparatus described above, embodiments of the invention may also be a computer program product comprising computer program instructions which, when executed by a processor, cause the processor to perform steps in a method according to various embodiments of the invention described in the "exemplary methods" section of this specification.
The computer program product may write program code for performing operations of embodiments of the present invention in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server.
Furthermore, embodiments of the present invention may also be a computer-readable storage medium, having stored thereon computer program instructions which, when executed by a processor, cause the processor to perform the steps in a method of mining history change records according to various embodiments of the present invention described in the "exemplary methods" section above in this specification.
The computer readable storage medium may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The basic principles of the present invention have been described above in connection with specific embodiments, however, it should be noted that the advantages, benefits, effects, etc. mentioned in the present invention are merely examples and not intended to be limiting, and these advantages, benefits, effects, etc. are not to be considered as essential to the various embodiments of the present invention. Furthermore, the specific details disclosed herein are for purposes of illustration and understanding only, and are not intended to be limiting, as the invention is not necessarily limited to practice with the above described specific details.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different manner from other embodiments, so that the same or similar parts between the embodiments are mutually referred to. For system embodiments, the description is relatively simple as it essentially corresponds to method embodiments, and reference should be made to the description of method embodiments for relevant points.
The block diagrams of the devices, systems, apparatuses, systems according to the present invention are merely illustrative examples and are not intended to require or imply that the connections, arrangements, configurations must be made in the manner shown in the block diagrams. As will be appreciated by one of skill in the art, the devices, systems, apparatuses, systems may be connected, arranged, configured in any manner. Words such as "including," "comprising," "having," and the like are words of openness and mean "including but not limited to," and are used interchangeably therewith. The terms "or" and "as used herein refer to and are used interchangeably with the term" and/or "unless the context clearly indicates otherwise. The term "such as" as used herein refers to, and is used interchangeably with, the phrase "such as, but not limited to.
The method and system of the present invention may be implemented in a number of ways. For example, the methods and systems of the present invention may be implemented by software, hardware, firmware, or any combination of software, hardware, firmware. The above-described sequence of steps for the method is for illustration only, and the steps of the method of the present invention are not limited to the sequence specifically described above unless specifically stated otherwise. Furthermore, in some embodiments, the present invention may also be embodied as programs recorded in a recording medium, the programs including machine-readable instructions for implementing the methods according to the present invention. Thus, the present invention also covers a recording medium storing a program for executing the method according to the present invention.
It is also noted that in the systems, devices and methods of the present invention, components or steps may be disassembled and/or assembled. Such decomposition and/or recombination should be considered as equivalent aspects of the present invention. The previous description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects without departing from the scope of the invention. Thus, the present invention is not intended to be limited to the aspects shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing description has been presented for purposes of illustration and description. Furthermore, this description is not intended to limit embodiments of the invention to the form disclosed herein. Although a number of example aspects and embodiments have been discussed above, a person of ordinary skill in the art will recognize certain variations, modifications, alterations, additions, and subcombinations thereof.

Claims (10)

1. A non-invasive quasi-real-time monitoring method based on ASM byte code instrumentation is characterized by comprising the following steps:
key information in the execution process of the monitored Java method is collected in a non-invasive mode through a Java technology and an ASM framework, and the collected key information is transmitted to a message queue realized on the basis of a RocketMQ;
the key information is sent to a monitoring service platform back-end program through a message queue realized based on the RocketMQ;
the key information of the message queue is consumed and subjected to lasting treatment through a monitoring service platform back-end program, and is stored into an RDBMS relational database;
obtaining key information from the RDBMS relational database by using an elastic search engine for quasi-real-time searching and analysis;
and displaying the analysis result to a front-end page of the monitoring service platform through the ECharts visualization tool.
2. The method according to claim 1, wherein the collecting key information in the monitored Java method execution process in a non-invasive manner through the Java agent technology and ASM framework includes:
the entry function of the JavaAgents program is realized through the JavaAgentMain class;
realizing the operation logic of the byte code by using an ASM framework through a ByteCode converter class;
analyzing the information of the Java method in a byte code mode through a ByteCode method tester class;
entering a monitored Java method and enhancing byte codes;
and when the logic execution of the monitored Java method is finished, ending the Java method and enhancing the byte code to obtain the monitored key information when the Java method is executed.
3. The method according to claim 2, wherein the implementation of the portal function of the java agent program through the java agentmain class includes:
when the Java program runs, the Java virtual machine calls a premain method with a String type entry and an Instrumentation type entry on the Java AgentMain class;
if the JavaAgentMain class does not realize a premain method with String type entry and Instrumentation type entry, the Java virtual machine calls the premain method only comprising String type entry;
the path information of the Java AgentMain class is configured into a MANIFEST.MF file, wherein the MANIFEST.MF file is used for defining extension or archive package related data in a Java program.
4. The method of claim 2, wherein the implementing byte code operation logic with ASM framework by a bytecode converter class comprises:
the bytecode converter class implements the operation logic of the bytecode with the class ClassReader, classWriter and classinitiator provided within the ASM framework.
5. The method of claim 4, wherein parsing the Java method information in a bytecode manner through a bytecode method viewer class, comprising:
in the process of loading and starting Java programs, monitoring all Java methods of all classes, and acquiring names, method names, entry types, entry values, return types and method return values of all the classes, wherein the entry types, the entry values, the return types and the method return values are described as a section of fixed character string by an ASM framework;
according to the description of the ASM framework official document on the fixed character string, analyzing the character strings of the parameter entering type, the parameter entering value, the return type and the method return value by using a regular expression;
and generating a globally unique identification ID of the monitored Java method by utilizing the analyzed method information.
6. The method of claim 5, wherein the entering the monitored Java method and enhancing the bytecode comprises:
by overwriting the onmethod enter method in the sub-class ByteCode method Viactor inheriting the parent class AdviceAdapter, it is used to set the start time when entering the Java method being monitored;
using byte codes to pile the logic with the set start time to the start of the monitored Java method when entering;
creating and initializing an object type array with the same capacity as the monitored Java method parameter by using byte codes;
all the entry information of the monitored Java method is added into the created object type array through byte codes.
7. The method of claim 6, wherein when the monitored Java method logic is executed, ending the Java method and enhancing the bytecode to obtain the monitored key information when the Java method is executed, comprising:
when the monitored Java method logic is executed, ending the Java method, and determining that the method is time-consuming to execute;
the method of rewriting onmethod exit uses byte code to obtain class name, method name, entry type, entry parameter value, return type, method return value and method execution time consuming and output to outside as key information monitored when Java method is executed.
8. A non-invasive quasi-real-time monitoring system based on ASM bytecode instrumentation, comprising:
the key information acquisition and transmission module is used for acquiring key information in the execution process of the monitored Java method in a non-invasive mode through a Java technology and an ASM framework, and transmitting the acquired key information to a message queue realized on the basis of the RocketMQ;
the key information sending module is used for sending the key information to a monitoring service platform back-end program through a message queue realized based on the RocketMQ;
the key information storage module is used for carrying out consumption and persistence processing on key information of the message queue through a monitoring service platform back-end program and storing the key information into the RDBMS relational database;
the key information analysis module is used for acquiring key information from the RDBMS relational database by utilizing the elastic search engine to perform quasi-real-time search and analysis;
and the visual display module is used for displaying the analysis result to a front-end page of the monitoring service platform through the ECharts visual tool.
9. A computer readable storage medium, characterized in that the storage medium stores a computer program for executing the method of any of the preceding claims 1-7.
10. An electronic device, the electronic device comprising:
a processor;
a memory for storing the processor-executable instructions;
the processor is configured to read the executable instructions from the memory and execute the instructions to implement the method of any of the preceding claims 1-7.
CN202310902308.4A 2023-07-21 2023-07-21 Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation Pending CN117112341A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310902308.4A CN117112341A (en) 2023-07-21 2023-07-21 Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310902308.4A CN117112341A (en) 2023-07-21 2023-07-21 Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation

Publications (1)

Publication Number Publication Date
CN117112341A true CN117112341A (en) 2023-11-24

Family

ID=88804632

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310902308.4A Pending CN117112341A (en) 2023-07-21 2023-07-21 Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation

Country Status (1)

Country Link
CN (1) CN117112341A (en)

Similar Documents

Publication Publication Date Title
CN108304201B (en) Object updating method, device and equipment
US7917815B2 (en) Multi-layer context parsing and incident model construction for software support
KR100692172B1 (en) Universal string analyzer and method thereof
US20100262956A1 (en) Software development support apparatus, function extension method and storage medium for storing function extension program
CN113051514B (en) Element positioning method and device, electronic equipment and storage medium
CN114036183A (en) Data ETL processing method, device, equipment and medium
CN111443901A (en) Business expansion method and device based on Java reflection
CN107391528B (en) Front-end component dependent information searching method and equipment
US9367307B2 (en) Staged points-to analysis for large code bases
CN109144648B (en) Method and system for uniformly performing feature extraction
CN114416481A (en) Log analysis method, device, equipment and storage medium
CN113962597A (en) Data analysis method and device, electronic equipment and storage medium
CN111666201A (en) Regression testing method, device, medium and electronic equipment
CN111126008A (en) XSD-based code generation method and device, computer equipment and storage medium
CN110716866A (en) Code quality scanning method and device, computer equipment and storage medium
CN117112341A (en) Non-invasive quasi-real-time monitoring method and system based on ASM byte code instrumentation
CN115237399A (en) Method for collecting data, storage medium, processor and engineering vehicle
CN114238391A (en) Data paging query method and device, electronic equipment and storage medium
CN114063943A (en) Data transmission system, method, device, medium, and apparatus
CN114090514A (en) Log retrieval method and device for distributed system
WO2017175247A1 (en) Method and system for generating content from search results rendered by a search engine
CN113568678A (en) Method and device for dynamically loading resources and electronic equipment
CN113220586A (en) Automatic interface pressure test execution method, device and system
CN113656044B (en) Android installation package compression method and device, computer equipment and storage medium
JP3540241B2 (en) Application startup menu definition file generation device and application startup menu generation device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication