Remote application problem troubleshooting method and system based on JavaAgent
Through the remote application problem troubleshooting system based on JavaAgent, dynamically edit the class bytecode of Java applications and insert the log printing code, the troubleshooting problems caused by the small amount of Java application logs and environment restrictions on the remote server are solved, and fast and effective problem location and troubleshooting are achieved.
Patent Information
- Application Number
- CN202411648094.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-04-18
Smart Images

Figure CN119847799A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a JavaAgent-based remote application problem troubleshooting method and system. Background Art
[0002] In daily software development work, Java applications are usually deployed to remote servers. When a problem occurs in a Java application deployed on a remote server, it is necessary to locate and solve the problem. Common problem location methods include problem log analysis and remote debugging. However, when locating Java application problems on a remote server, the following situations are often encountered:
[0003] The Java application prints few logs, which are not sufficient to locate the specific location of the problem.
[0004] Since the remote server is deployed in a different location and is not connected to the network where the software developers are located, it is impossible to remotely debug the Java application;
[0005] The server and its network security policy limit remote debugging.
[0006] When the cause of a Java application problem cannot be directly located through problem log analysis and remote debugging, it often takes a lot of time and effort to find the cause of the problem.
[0007] The pain points and difficulties of troubleshooting Java applications deployed on remote servers are that there are few Java application logs and environmental restrictions make remote debugging impossible. Therefore, how to remotely troubleshoot Java applications has become a technical challenge. Summary of the invention
[0008] The present invention proposes the following technical solutions to address one or more technical deficiencies in the above-mentioned prior art.
[0009] Based on the first aspect of the present invention, a system for remote application problem troubleshooting based on JavaAgent is proposed, comprising a problem diagnosis subsystem and a Java application, wherein the problem diagnosis subsystem comprises a configuration management module, a class bytecode management module and a program mounting module;
[0010] Wherein, the configuration management module is used to manage the Java class configuration list;
[0011] The class bytecode management module is used to monitor the class bytecode loading action of the Java application and extract the class bytecode to be loaded, and insert the log printing code into the Java method corresponding to the class bytecode according to the Java class configuration list;
[0012] The program mounting module is used to mount the problem diagnosis subsystem into the Java application of the target server.
[0013] Mounting the problem diagnosis subsystem to the Java application of the target server can effectively avoid troubleshooting problems caused by server network connectivity failure and security policy restrictions.
[0014] Furthermore, the management Java class configuration list includes the management Java class name, Java method name, parameter list and log printing code insertion position.
[0015] Through the configuration file, you can support flexible configuration of log information by class and method, and output debug logs as needed.
[0016] Furthermore, the configuration management module includes a plurality of class nodes for configuring Java class names, and one class node configures one Java class.
[0017] Furthermore, the class node has multiple attributes, including a method attribute, a position attribute, and a params attribute.
[0018] Furthermore, the method attribute is used to configure a Java method so that a log printing code is inserted into the class node;
[0019] The position attribute is used to configure the insertion position of the log printing code;
[0020] The params attribute is used to identify a Java method in a polymorphic Java class.
[0021] Furthermore, the params attribute of the classes node is configured only when there are multiple methods with the same name in the Java class.
[0022] Based on the second aspect of the present invention, a method for remote application problem troubleshooting using any of the above-mentioned systems is also proposed, comprising:
[0023] S1: The problem diagnosis subsystem is mounted into the Java application of the target server through the JavaAgent plug-in and the program mounting module;
[0024] S2: The problem diagnosis subsystem dynamically edits the class bytecode of the Java application of the target server through the Javassist class library;
[0025] S3: the problem diagnosis subsystem monitors the Java application of the target server and intercepts the class bytecode when the Java application loads the class bytecode, and then inserts a log printing code into the class bytecode according to the position attribute;
[0026] S4: The Java application of the target server loads and calls the class bytecode, and outputs a problem log information file for troubleshooting.
[0027] The problem diagnosis subsystem is mounted to the Java application corresponding to the remote server through the JavaAgent plug-in, which effectively avoids the problem of being unable to use remote debugging due to environmental restrictions. The problem diagnosis subsystem can be hot-mounted on demand in real time without restarting the application, without affecting the current accessing users, and can maximize the retention of the problem site.
[0028] Based on the third aspect of the present invention, a computer program product is also proposed, on which there are one or more computer programs, and when the one or more computer programs are executed by a computer processor, they implement any of the methods described above.
[0029] The technical effect of the present invention is that by mounting the problem diagnosis subsystem into the Java application in real time, the debug log is directly output on demand in the Java application, thereby maximally avoiding the troubleshooting problems caused by server network or security policy restrictions, and helping R&D personnel to locate problems quickly and effectively, which has broad prospects for Java application problems deployed on the server side. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Other features, objects and advantages of the present application will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings.
[0031] Figure 1 The present invention provides a system framework diagram of a JavaAgent-based remote application problem troubleshooting method according to an embodiment of the present invention.
[0032] Figure 2 It is a logical relationship diagram between various modules of a problem diagnosis subsystem and a Java application provided according to an embodiment of the present invention.
[0033] Figure 3 The present invention provides a flow chart of a method for troubleshooting remote application problems based on JavaAgent according to an embodiment of the present invention.
[0034] Figure 4 It is a structural diagram of a computer system suitable for implementing an electronic device of an embodiment of the present application. DETAILED DESCRIPTION
[0035] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It should also be noted that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0036] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0037] Figure 1 The present invention shows a remote application problem troubleshooting system based on JavaAgent, including a problem diagnosis subsystem a and a Java application b. The problem diagnosis subsystem b includes a configuration management module c, a class bytecode management module d and a program mounting module e. The logical relationship between the modules of the problem diagnosis subsystem a and the Java application b is as follows: Figure 2 As shown, the problem diagnosis subsystem is mounted into the Java application of the target server through the program mounting module.
[0038] In a specific embodiment, the configuration management module c is configured to manage a Java class configuration list.
[0039] In a specific embodiment, the class bytecode management module d is configured to monitor the class bytecode loading action of the Java application and extract the class bytecode to be loaded, and insert the log printing code into the Java method corresponding to the class bytecode according to the Java class configuration list.
[0040] In a specific embodiment, the program mounting module e is configured to mount the problem diagnosis subsystem into a Java application of the target server.
[0041] It should be noted that the management Java class configuration list includes the management Java class name, Java method name, parameter list and log printing code insertion position.
[0042] It should be noted that the configuration management module includes multiple class nodes for configuring Java class names, and one class node configures one Java class.
[0043] In a specific embodiment, if multiple Java classes are to be configured, multiple class nodes are used.
[0044] It should be noted that the class node has multiple attributes, including a method attribute, a position attribute, and a params attribute.
[0045] It should be noted that the Java method is a code block used to encapsulate specific functions, which has the effect of reducing code redundancy and improving code reusability and maintainability.
[0046] It should be noted that the method attribute is used to configure the Java method so that the log printing code is inserted into the class node;
[0047] The position attribute is used to configure the insertion position of the log printing code;
[0048] The params attribute is used to identify a Java method in a polymorphic Java class.
[0049] In a specific embodiment, the code inserted in the configuration management module is:
[0050]
[0051]
[0052] The position attribute and the method attribute are required attributes. start indicates that the insertion position is the first line of the method, and end indicates that the insertion position is the end of the method. Filling in a specific number indicates inserting by line number.
[0053] In a specific embodiment, the core code for editing the class bytecode is:
[0054]
[0055]
[0056] In a specific embodiment, the core code of the program mounting module is:
[0057] " / / Extract Java application port
[0058] String port = args[0];
[0059] / / Mount the problem diagnosis subsystem to the Java application
[0060] VirtualMachine virtualMachine=VirtualMachine.attach(port);
[0061] virtualMachine.loadAgent(" / usr / local / java-agent.jar");".
[0062] It should be noted that the params attribute of the classes node is configured only when there are multiple methods with the same name in the Java class.
[0063] Reference below Figure 3 , which shows a flow chart of a method for remote application problem troubleshooting based on JavaAgent, including the following steps:
[0064] S1: The problem diagnosis subsystem is mounted into the Java application of the target server through the JavaAgent plug-in and the program mounting module;
[0065] S2: The problem diagnosis subsystem dynamically edits the class bytecode of the Java application of the target server through the Javassist class library;
[0066] S3: the problem diagnosis subsystem monitors the Java application of the target server and intercepts the class bytecode when the Java application loads the class bytecode, and then inserts a log printing code into the class bytecode according to the position attribute;
[0067] S4: The Java application of the target server loads and calls the class bytecode, and outputs a problem log information file for troubleshooting.
[0068] It should be noted that by mounting the problem diagnosis subsystem to the Java application corresponding to the remote server through the JavaAgent plug-in, the problem of being unable to use remote debugging due to environmental restrictions is effectively avoided. In addition, the problem diagnosis subsystem can be hot-mounted on demand in real time without restarting the application, without affecting the currently accessing users, and can maximize the retention of the problem site.
[0069] It should be noted that the JavaAgent plug-in can intercept and modify the bytecode when loading Java files, and can change the loaded class bytecode during operation. It must be run on a Java application, complete the loading through the JVMTool Interface, and modify the target code through the Java Programming Language Instrumentation ServicesAgent.
[0070] It should be noted that the dynamic editing of the class bytecode of the problem diagnosis subsystem is specifically as follows: reading the class bytecode to be edited from the ClassPool, reversely generating a CTClass object, and obtaining the Java class method list from the CTClass object, inserting the log printing code into the corresponding Java method, and then returning the dynamically edited class to the Java class loader.
[0071] It should be noted that the problem diagnosis subsystem is mounted into the Java application of the target server through the JavaAgent plug-in and the program mounting module; specifically, the process ID of the target server is obtained, the attach method of the JavaAgent plug-in is called to connect to the target server, and then the loadAgent method is called to load the problem diagnosis subsystem into the Java application of the target server.
[0072] It should be noted that the methods for troubleshooting log information files include:
[0073] Locate the specific code line where the abnormal problem occurs in the Java application on the target server, add the log printing code of the relevant variables to the line above the specific code line, and then determine the specific cause of the abnormal problem through the relevant variable values of the log information file;
[0074] If you cannot locate the specific line of code where the exception occurs in the Java application on the target server, and can only locate the Java method that throws the exception, add method input parameter log printing code to the first line of the Java method that throws the exception, obtain the value of the specific Java method input parameter through the log information file, simulate the relevant input parameter through the local R&D environment, and locate the specific cause of the problem.
[0075] It should be noted that the present invention solves the problem that it is difficult to locate the specific location of the problem in the Java application deployed on the remote server due to the small number of printed logs, and the problem of being unable to remotely debug due to the poor network connection of the Java application deployed in a remote location or the network or security policy restrictions of the remote server. It is beneficial for R&D personnel to quickly locate the problem and output the problem log on demand.
[0076] Reference below Figure 4 , which shows a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application. Figure 4 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0077] like Figure 4As shown, the computer system includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 into a random access memory (RAM) 403. Various programs and data required for system operation are also stored in the RAM 403. The CPU 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0078] The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, etc.; an output section 407 including a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage section 408 as needed.
[0079] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 409, and / or installed from the removable medium 411. When the computer program is executed by the central processing unit (CPU) 401, the above functions defined in the method of the present application are executed. It should be noted that the computer-readable storage medium of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, - but not limited to - a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wireline, optical cable, RF, etc., or any suitable combination of the foregoing.
[0080] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0081] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0082] The modules involved in the embodiments of the present application may be implemented by software or by hardware.
[0083] As another aspect, the present application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiment; or it may exist independently without being assembled into the electronic device. The above computer-readable storage medium carries one or more programs. When the above one or more programs are executed by the electronic device, the electronic device: the problem diagnosis subsystem is mounted into the Java application of the target server through the JavaAgent plug-in and the program mounting module; and the class bytecode of the Java application of the target server is dynamically edited through the Javassist class library; the Java application of the target server is monitored and the class bytecode is intercepted when the Java application loads the class bytecode, and then the log printing code is inserted into the class bytecode according to the position attribute; the Java application of the target server loads and calls the class bytecode to output the problem log information file for problem troubleshooting.
[0084] Finally, it should be noted that the above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A remote application problem troubleshooting system based on JavaAgent, characterized in that: It includes a problem diagnosis subsystem and a Java application, wherein the problem diagnosis subsystem includes a configuration management module, a class bytecode management module and a program mounting module; Wherein, the configuration management module is used to manage the Java class configuration list; The class bytecode management module is used to monitor the class bytecode loading action of the Java application and extract the class bytecode to be loaded, and insert the log printing code into the Java method corresponding to the class bytecode according to the Java class configuration list; The program mounting module is used to mount the problem diagnosis subsystem into the Java application of the target server.
2. The system according to claim 1, characterized in that The management Java class configuration list includes the management Java class name, Java method name, parameter list and log printing code insertion position.
3. The system according to claim 1, characterized in that The configuration management module includes a plurality of class nodes for configuring Java class names, and one class node configures one Java class.
4. The system according to claim 3, characterized in that The class node has multiple attributes, including a method attribute, a position attribute, and a params attribute.
5. The system according to claim 4, characterized in that The method attribute is used to configure the Java method so that the log printing code is inserted into the class node; The position attribute is used to configure the insertion position of the log printing code; The params attribute is used to identify a Java method in a polymorphic Java class.
6. The system according to claim 5, characterized in that The params attribute of the classes node is configured only when there are multiple methods with the same name in the Java class.
7. A method for remote application problem troubleshooting according to the system according to any one of claims 1 to 6, characterized in that: include: S1: The problem diagnosis subsystem is mounted into the Java application of the target server through the JavaAgent plug-in and the program mounting module; S2: The problem diagnosis subsystem dynamically edits the class bytecode of the Java application of the target server through the Javassist class library; S3: the problem diagnosis subsystem monitors the Java application of the target server and intercepts the class bytecode when the Java application loads the class bytecode, and then inserts a log printing code into the class bytecode according to the position attribute; S4: The Java application of the target server loads and calls the class bytecode, and outputs a problem log information file for troubleshooting.
8. A computer program product having one or more computer programs thereon, characterized in that: The one or more computer programs implement the method of claim 7 when executed by a computer processor.
Citation Information
Patent Citations
Micro-service link calling method, system, equipment and medium
CN114237770A
Dynamic point burying method and device, electronic equipment and readable storage medium
CN118093340A
Methods and apparatus for analyzing software interface usage
US20080134156A1