Java application monitoring method and device, storage medium and electronic device
By starting monitoring and acquisition scripts in Java applications, collecting and processing monitoring indicators of Java processes, the problem of non-universal monitoring indicators of Java applications is solved, and comprehensive monitoring and operation security guarantees for Java applications are achieved.
Patent Information
- Application Number
- CN202111348854.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-15
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-11-15
AI Technical Summary
In the prior art, the monitoring indicators of Java applications cannot be generalized in various Java applications, and there is a lack of monitoring of some key indicators, resulting in inadequate monitoring, difficult related operation risks and early detection, which in turn leads to production failures.
Provides a Java application monitoring method, which starts the monitoring and acquisition script through a preset time period, collects the currently valid running Java process, determines the monitoring object and sets the name, collects various monitoring indicators, and outputs data files to the monitoring tool, performs data processing and exception judgment, and issues alarm notifications.
It realizes all-round monitoring of various Java applications, ensures the operation of Java applications and products, promptly discovers and deals with potential risks, and avoids production failures.
Smart Images

Figure CN114048099B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a Java application monitoring method and device, a storage medium and an electronic device. Background Art
[0002] Java applications and products are systems developed based on the Java programming language. Due to the many advantages of Java programming such as portability and scalability, Java applications and products are widely developed and used.
[0003] Java applications and products run on tens of thousands of JVM instances and are important operation and maintenance objects. Comprehensive and effective monitoring of JVM is an important task in operation and maintenance management. However, in the existing technology, the monitoring indicators for Java applications cannot be universally used in various Java applications, and the monitoring of some key indicators is lacking, which can easily lead to inadequate monitoring and related operation risks cannot be discovered early, thus causing production failures. Summary of the invention
[0004] In view of this, the present invention provides a Java application monitoring method, through which various Java applications can be monitored, thereby ensuring the running security of Java applications and products.
[0005] The present invention also provides a Java application monitoring device to ensure the implementation and application of the above method in practice.
[0006] A Java application monitoring method, comprising:
[0007] Start the preset monitoring collection script according to the preset time period;
[0008] Apply the monitoring and collection script to collect the currently running Java processes;
[0009] Determine the monitoring object corresponding to the Java process, and set the monitoring object name of the monitoring object;
[0010] Collecting various monitoring indicators corresponding to the monitoring object, and outputting monitoring data files corresponding to each monitoring indicator to a preset monitoring tool;
[0011] Using the monitoring tool to process the monitoring data file to obtain a processed monitoring data file;
[0012] Based on preset monitoring rules, determine whether the monitoring data file has any abnormality;
[0013] If there is an abnormality in the monitoring data file, an alarm notification corresponding to the monitoring object is issued.
[0014] In the above method, optionally, applying the monitoring collection script to collect the currently validly running Java processes includes:
[0015] Obtaining preset process information, and extracting a first keyword contained in the process information;
[0016] Acquire a preset process list based on the first keyword, and detect whether the process list includes at least one Java process;
[0017] When the process list includes at least one Java process, obtaining a preset blacklist;
[0018] Based on the blacklist, valid Java processes in the process list are determined, and the monitoring collection script is applied to collect valid Java processes in the process list.
[0019] In the above method, optionally, the step of setting the monitored object name of the monitored object includes:
[0020] Based on the first keyword, determining an application type of a monitoring object corresponding to the Java process;
[0021] Extracting instance information of the application type;
[0022] When the instance information of the application type is successfully extracted, obtaining at least one second keyword from the instance information, and forming an instance name by each of the second keywords, wherein the second keyword is an instance keyword of the JVM instance corresponding to the Java process;
[0023] Based on the application type and the instance name, a monitoring object name corresponding to the monitoring object is formed;
[0024] When extracting the instance information of the application type fails, obtaining port information of a monitoring port for monitoring the Java process;
[0025] Based on the application type and the port information, a monitoring object name corresponding to the monitoring object is constructed.
[0026] In the above method, optionally, the collecting of each monitoring indicator corresponding to the monitoring object includes:
[0027] Acquire a third keyword contained in the process information, where the third keyword is a log keyword used to determine whether a GC log exists;
[0028] Based on the third keyword, determining whether there is a GC log of the JVM instance corresponding to the Java process;
[0029] If there is a GC log of the JVM instance corresponding to the Java process, the FullGC monitoring indicators within a preset time period are obtained based on the GC log; the FullGC monitoring indicators include the number of FullGCs, the average FullGC time consumption, the total FullGC time consumption, the Heap usage rate after FullGC, and the Heap recovery rate after FullGC;
[0030] If there is no GC log of the JVM instance corresponding to the Java process, determining the FullGC monitoring index within the preset time period based on the FullGC monitoring index information contained in the preset temporary file;
[0031] Apply the preset jstat command to obtain the Heap monitoring indicators of the Heap, where the Heap is the heap memory of the Java process, and the Heap monitoring indicators include the Perm usage rate, the MetaSpace usage rate, and the Old usage rate;
[0032] Obtain the maximum number of files that can be opened by the Java process and the number of currently opened file handles;
[0033] Based on the maximum number of openable file handles of the Java process and the current number of open file handles, the usage rate of the open file handles is calculated.
[0034] In the above method, optionally, obtaining the FullGC monitoring indicator within a preset time period based on the GC log includes:
[0035] Obtaining a GC log output path of the JVM instance, and obtaining a GC log based on the GC log output path;
[0036] Determine the last scan position recorded in the GC log, scan the GC log with the last scan position as the starting position, and obtain the log content of the GC log within the preset time period;
[0037] The GC log content is analyzed to obtain the FullGC monitoring index within the preset time period.
[0038] In the above method, optionally, determining the FullGC monitoring index within the preset time period based on the FullGC monitoring index information contained in the preset temporary file includes:
[0039] Obtain the historical FullGC monitoring indicators recorded when each monitoring indicator corresponding to the monitoring object was collected last time and contained in the temporary file;
[0040] A current FullGC monitoring index corresponding to the monitoring object is determined, and based on the current FullGC monitoring index and the historical FullGC monitoring index, a FullGC monitoring index within the preset time period is calculated.
[0041] In the above method, optionally, the application of a preset jstat command to obtain the Heap monitoring indicator of the Heap includes:
[0042] Determine the perm area size and the used size of the perm area of the largest perm area, the MetaSpace area size and the used size of the MetaSpace area of the largest MetaSpace area, and the Old area size and the used size of the Old area of the largest Old area in the JVM instance;
[0043] Calculating a perm zone usage rate of the perm zone based on the perm zone size and the perm zone usage size;
[0044] Calculate the MetaSpace zone usage rate of the MetaSpace zone based on the MetaSpace zone size and the MetaSpace zone usage size;
[0045] Based on the Old area size and the Old area usage size, an Old area usage rate of the Old area is calculated.
[0046] A Java application monitoring device, comprising:
[0047] A startup unit, used to start a preset monitoring collection script according to a preset time period;
[0048] A first collection unit, used to collect a Java process of a preset server by applying the monitoring collection script;
[0049] A setting unit, used to determine a monitoring object corresponding to the Java process, and set a monitoring object name corresponding to the monitoring object;
[0050] A second collection unit, used to collect various monitoring indicators corresponding to the monitoring object, and output monitoring data files corresponding to each of the monitoring indicators to a preset monitoring tool;
[0051] A processing unit, configured to use the monitoring tool to perform data processing on the monitoring data file to obtain a processed monitoring data file;
[0052] A judging unit, configured to judge whether the monitoring data file has an abnormality based on a preset monitoring rule;
[0053] The alarm unit is used to issue an alarm notification corresponding to the monitored object if there is an abnormality in the monitoring data file.
[0054] A storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the Java application monitoring method as described above.
[0055] An electronic device includes a memory and one or more instructions, wherein the one or more instructions are stored in the memory and are configured to be executed by one or more processors to execute the Java application monitoring method as described above.
[0056] Compared with the prior art, the present invention has the following advantages:
[0057] Based on the embodiment provided by the present invention, during the Java application monitoring process, a preset monitoring and collection script is started according to a preset time period, and the monitoring and collection script is used to collect the currently validly running Java process; the monitoring object corresponding to the Java process is determined, and the monitoring object name of the monitoring object is set; various monitoring indicators corresponding to the monitoring object are collected, and the monitoring data files corresponding to the various monitoring indicators are output to a preset monitoring tool; the monitoring tool is used to process the monitoring data file to obtain a processed monitoring data file; based on the preset monitoring rules, it is determined whether the monitoring data file has an abnormality; if the monitoring data file has an abnormality, an alarm notification corresponding to the monitoring object is issued.
[0058] By using the Java application monitoring method provided by the present invention, various Java processes currently running effectively are collected through monitoring and collection scripts, and various monitoring indicators of the monitoring objects corresponding to each Java process are collected. A monitoring tool is used to process the collected monitoring indicators to realize monitoring of various Java applications, thereby ensuring the safe operation of Java applications and products. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0060] Figure 1 A method flow chart of a Java application monitoring method provided by an embodiment of the present invention;
[0061] Figure 2 Another method flow chart of a Java application monitoring method provided by an embodiment of the present invention;
[0062] Figure 3A method flow chart of another method of a Java application monitoring method provided by an embodiment of the present invention;
[0063] Figure 4 Another method flow chart of a Java application monitoring method provided by an embodiment of the present invention;
[0064] Figure 5 A device structure diagram of a Java application monitoring device provided by an embodiment of the present invention;
[0065] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "comprise one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0068] JVM: It is the abbreviation of JAVA Virtual Machine. It is a fictional computer that is realized by simulating various computer functions on an actual computer. After the introduction of the Java language virtual machine, the Java language needs to be recompiled when running on different platforms. The Java language uses the Java virtual machine to shield the information related to the specific platform, so that the Java compiler only needs to generate the target code (bytecode) that runs on the Java virtual machine, and can run on multiple platforms without modification.
[0069] JMX (Java Management Extensions): is a framework for embedding management functions into applications. JMX is a set of standard agents and services. Users can use JMX in any Java application to monitor and manage JAVA applications and JVM. JMX has the following uses:
[0070] 1) Monitor the running status and related statistics of the application.
[0071] 2) Modify the configuration of the application (without restarting).
[0072] 3) Notification and processing when status changes or errors occur.
[0073] JConsole and JVisualVM monitor JAVA applications and JVM information through JMX. JConsole can monitor the application's heap memory usage, number of threads, number of classes, view certain configuration information, and even dynamically modify the configuration.
[0074] JConsole (Java Monitoring and Management Console): is a JMX-based visual monitoring and management tool. JConsole is a built-in management tool of JDK. You can open JConsole by running it directly in JAVA_HOME / bin.
[0075] JConsole provides two connection methods, one is to connect to the local process, the other is to connect to the remote program. Local connection does not require a password, just select the corresponding JVM program, and remote connection is carried out through the JMX protocol.
[0076] The present invention can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, distributed computing environments including any of the above devices or devices, etc.
[0077] The embodiment of the present invention provides a Java application monitoring method, which can be applied to various system platforms, and its execution subject can be a processor of a computer terminal or various mobile devices. The method flow chart of the method is as follows: Figure 1 As shown, specifically including:
[0078] S101: Start a preset monitoring collection script according to a preset time period.
[0079] In the embodiment provided by the present invention, the monitoring collection script can be called up on the server at a certain execution frequency through the server crontab task or monitoring tool (or other operation and maintenance tool). The collection frequency can be parameterized as needed, and the default collection frequency is: once every 2 minutes.
[0080] S102: Apply the monitoring collection script to collect the currently validly running Java processes.
[0081] According to the running monitoring collection script, the Java processes on the server executed by the monitoring collection script are collected, including effectively running and invalidly running Java processes, and the invalidly running Java processes are excluded, and only the currently effectively running Java processes are collected.
[0082] Specifically, the application of the monitoring collection script to collect the currently validly running Java processes includes:
[0083] Obtaining preset process information, and extracting a first keyword contained in the process information;
[0084] Acquire a preset process list based on the first keyword, and detect whether the process list includes at least one Java process;
[0085] When the process list includes at least one Java process, obtaining a preset blacklist;
[0086] Based on the blacklist, valid Java processes in the process list are determined, and the monitoring collection script is applied to collect valid Java processes in the process list.
[0087] In the embodiment provided by the present invention, by identifying the first keyword in the preset process information, a Java process list corresponding to the first keyword is obtained. If there is at least one Java process in the Java process list, each Java process in the Java process list is compared with the Java process in the preset blacklist to identify the Java process that does not need to be monitored, so as to determine the valid Java process in the process list, and apply the monitoring collection script to collect the valid Java process in the process list. If there is no Java process in the Java process list, there is no need to perform subsequent collection actions, and this collection execution is skipped.
[0088] The following is the program code implementation for obtaining a list of Java processes that need to be monitored on the server by excluding irrelevant Java processes.
[0089] #Define a list of Java processes to exclude from monitoring
[0090] V_EXCLUDE_JAVA_PROC="AppmonAgent|nft|NodeManager|JFServer"
[0091] #Get the list of Java processes that need to be monitored
[0092] ps-fu${USER}|grep-w"java"|grep-v"grep"|grep-Evw"${V_EXCLUDE_JAVA_PROC}"
[0093] Get the Java process list through process keywords and exclude Java processes that do not need to be monitored through the blacklist. By scanning the processes running on the system, the Java applications that need to be monitored can be automatically identified. It has the advantages of being adaptive and maintenance-free, and supports automatically incorporating monitored objects into the monitoring scope without human intervention.
[0094] S103: Determine the monitoring object corresponding to the Java process, and set the monitoring object name of the monitoring object.
[0095] In the embodiment provided by the present invention, after the valid Java process is identified, the server where the Java process is located is used as the monitoring object. In order to ensure that the monitoring object name remains unchanged after the Java process is restarted so that the monitoring indicators continue to be connected according to the monitoring object, a relatively stable and unique monitoring object name needs to be defined for the monitoring object.
[0096] S104: Collecting various monitoring indicators corresponding to the monitoring object, and outputting monitoring data files corresponding to the various monitoring indicators to a preset monitoring tool.
[0097] S105: Using the monitoring tool to process the monitoring data file to obtain a processed monitoring data file.
[0098] According to the specification requirements, each indicator of the monitored object is written into the specified monitoring data file, so that the monitoring tool can scan the monitoring data file and collect the data of each monitoring indicator to the monitoring platform.
[0099] The following is an example of outputting file handle usage monitoring indicators:
[0100] echo "cls<JAVA_OPENFILES> obj<${v_inst}>par<OPEN_FILE_RATIO> val<${v_open_file_ratio}>">>${V_MONITOR_LOG}, where:
[0101] cls<JAVA_OPENFILES> The field defines the monitoring indicator type as: JAVA_OPENFILES (the number of file handles opened by the Java process), the obj<${v_inst}> field defines the monitoring object as: ${v_inst}, par<OPEN_FILE_RATIO> The field defines the output monitoring indicator as: OPEN_FILE_RATIO (file handle usage rate), the "val<${v_open_file_ratio}>" field defines the monitoring object ${v_inst}, and the specific result value of the monitoring indicator OPEN_FILE_RATIO is: ${v_open_file_ratio}.
[0102] S106: Based on preset monitoring rules, determine whether the monitoring data file has any abnormality.
[0103] In the embodiment provided by the present invention, the server calls the monitoring tool so that the monitoring tool regularly scans the monitoring file storage directory through the network management protocol agent deployed on the local machine, and collects the newly generated collection result data to the monitoring platform. The monitoring platform makes an abnormal judgment on the monitoring data file according to the preset monitoring rules.
[0104] S107: If there is an abnormality in the monitoring data file, an alarm notification corresponding to the monitoring object is issued.
[0105] The monitoring platform analyzes, cleans, and processes the collected data, and determines whether there are any abnormalities in the monitoring indicators of the monitored objects based on the defined monitoring alarm rules. If there are any abnormalities, an alarm notification will be generated.
[0106] By calling the monitoring platform, you can also view the historical change curve of the monitoring indicators of each monitored object.
[0107] Based on the embodiment provided by the present invention, during the Java application monitoring process, a preset monitoring and collection script is started according to a preset time period, and the monitoring and collection script is used to collect the currently validly running Java process; the monitoring object corresponding to the Java process is determined, and the monitoring object name of the monitoring object is set; various monitoring indicators corresponding to the monitoring object are collected, and the monitoring data files corresponding to the various monitoring indicators are output to a preset monitoring tool; the monitoring tool is used to process the monitoring data file to obtain a processed monitoring data file; based on the preset monitoring rules, it is determined whether the monitoring data file has an abnormality; if the monitoring data file has an abnormality, an alarm notification corresponding to the monitoring object is issued.
[0108] By applying the embodiment provided by the present invention, various Java processes that are currently running effectively are collected through monitoring and collection scripts, and various monitoring indicators of the monitoring objects corresponding to each Java process are collected, and the monitoring tool is called to process the collected monitoring indicators to realize monitoring of various Java applications, thereby ensuring the safe operation of Java applications and products.
[0109] In the embodiments provided by the present invention, Figure 2 As shown, optionally, the setting of the monitoring object name of the monitoring object includes:
[0110] S201: Based on the first keyword, determine the application type of the monitoring object corresponding to the Java process.
[0111] To define a stable and unique name for the monitored object, it is necessary to extract stability feature information from the process information, permanently name the monitored object, and ensure that the monitored object name does not change due to restart.
[0112] Specifically, the monitoring object can be named according to a unified monitoring object (JVM instance) naming rule: <application type>: <instance name>. Therefore, it is necessary to first determine the application type of the monitoring object corresponding to the Java process based on the process information. The application type is used to distinguish the types of Java application products, such as: Weblogic, Tomcat, Conherence, WebSphere, etc. As shown in Table 1, it can be specifically distinguished by the keywords corresponding to the various product types in the process information. For example, if the keyword in the GC log is identified as Dweblogic.Name, the application type corresponding to the Java process is Weblogic.
[0113] Product Name Keywords WebLogic Dweblogic.Name Tomcat -Dcatalina Coherence DefaultCacheServer Zookeeper zookeeper Kafka Kafka Websphere Dwas
[0114] Table 1
[0115] S202: Determine whether instance information of the application type is extracted successfully.
[0116] After determining the application type corresponding to the Java process, the corresponding instance information can be extracted according to the application type, and the instance name can be determined according to the instance information.
[0117] When the instance information of the application type is successfully extracted, S203 to S204 are executed; when the instance information of the application type is failed to be extracted, S205 to S206 are executed.
[0118] S203: Acquire at least one second keyword from the instance information, and form an instance name with each of the second keywords.
[0119] Among them, the second keyword is the instance keyword of the JVM instance corresponding to the Java process.
[0120] The instance name can be composed of one or more keywords that distinguish instances. For example, the WeblogicServer name or the process listening port number can be used as the keyword to distinguish instances, so as to ensure that the monitoring object names can be effectively distinguished.
[0121] S204: Based on the application type and the instance name, form the monitoring object name corresponding to the monitoring object.
[0122] The application type for which the instance can be named according to the characteristics of the product, that is, the product type, such as Weblogic, Tomcat, Zookeeper, etc., is used to define different naming composition methods.
[0123] For example, for a Weblogic instance, specific instance information can be further extracted according to the characteristics of Weblogic, including: Domain name and Server name, so as to ensure that the monitoring object names can be effectively distinguished. Therefore, the naming composition of Weblogic can be: Weblogic:<Domain name>:<Server name>.
[0124] S205: Obtain the port information of the monitoring port for monitoring the Java process.
[0125] If the instance information of the application type cannot be extracted, at least one second keyword in the instance information cannot be obtained to distinguish instances. Since the listening port of the process is relatively fixed and generally still uses the original port after the process is restarted, the listening port of the process can be obtained as the keyword to distinguish the JVM instance.
[0126] S206: Based on the application type and the port information, form the monitoring object name corresponding to the monitoring object.
[0127] Among them, the port information includes a port keyword and a port number; according to the application type and the port information, the monitoring object name corresponding to the monitoring object is formed. For example, for a Tomcat instance, the naming is composed of the following: Tomcat:PORT_9001.
[0128] By extracting the characteristic information of stability in the process information, such as application type, instance information, and port information, etc., and using the extracted characteristic information to name the monitoring object, it is ensured that the monitoring object name does not change due to restart.
[0129] In the embodiments provided by the present invention, such as Figure 3As shown, optionally, the collecting of each monitoring indicator corresponding to the monitoring object includes:
[0130] S301: Acquire a third keyword included in the process information, where the third keyword is a log keyword used to determine whether a GC log exists.
[0131] In the embodiment provided by the present invention, the FullGC monitoring index can be obtained in two ways. If there is a GC log, the GC monitoring index is obtained through the GC log first. If there is no GC monitoring log, the GC monitoring index is obtained through the jstat command. Through the Xloggc keyword in the process information, it can be determined whether there is a GC log, and the GC log output path of the JVM instance can be extracted.
[0132] S302: Based on the third keyword, determine whether there is a GC log of the JVM instance corresponding to the Java process.
[0133] Determine whether there is a GC log according to the Xloggc keyword in the process information. If there is a GC log of the JVM instance corresponding to the Java process, execute S303; if there is no GC log of the JVM instance corresponding to the Java process, execute S304.
[0134] S303: Obtain FullGC monitoring indicators within a preset time period based on the GC log.
[0135] The FullGC monitoring indicators include the number of FullGCs, the average FullGC time consumption, the total FullGC time consumption, the Heap usage rate after FullGC, and the Heap recovery rate after FullGC.
[0136] FullGC is a relatively complete garbage collection that is triggered when the space in the Old area or Perm area of the JVM Heap is insufficient. It takes a long time. When FullGC is in progress, the Java process will suspend business processing, which will have a certain impact on business processing, such as longer transaction time and slower transaction processing. Therefore, the number of FullGCs is an indicator of FullGC, and the more FullGCs there are, the greater the impact on system operation. The total FullGC time consumption is an indicator of FullGC, which measures the total time consumed by FullGC during the inspection cycle. The longer the time, the greater the impact on business operation.
[0137] S304: Determine the FullGC monitoring index within the preset time period based on the FullGC monitoring index information included in the preset temporary file.
[0138] The temporary file mainly records the monitoring indicators such as the number of FullGCs, total FullGC time, average FullGC time, post-FullGC Heap usage, and FullGC Heap recovery rate since the process was started during the last collection. The monitoring indicator information of FullGC since the process was started recorded in the temporary file during the last collection and the monitoring indicator information of FullGC since the process was started obtained during this collection, such as the number of FullGCs, total FullGC time, average FullGC time, post-FullGC Heap usage, and FullGC Heap recovery rate, etc., are calculated by difference, and the monitoring indicator information of FullGCs, total FullGC time, average FullGC time, post-FullGC Heap usage, and FullGC Heap recovery rate, etc., within the collection time interval are calculated. The FullGC monitoring indicators collected this time are stored in the temporary file so that they can be calculated based on the FullGC monitoring indicators collected this time during the next collection.
[0139] S305: Apply the preset jstat command to obtain the Heap monitoring indicators of the Heap.
[0140] The Heap is the heap memory of the Java process, and the Heap monitoring index is a key index for evaluating whether the Heap has a capacity problem. The Heap monitoring index includes Perm usage, MetaSpace usage, and Old usage.
[0141] Specifically, the application uses the preset jstat command to obtain the Heap monitoring indicators of the Heap, including:
[0142] Determine the perm area size and the used size of the largest perm area, the MetaSpace area size and the used size of the MetaSpace area, and the Old area size and the used size of the largest Old area in the JVM instance.
[0143] Through the jstat command: v_max_perm_size = $(jstat -gcpermcapacity${v_pid}|grep -v "PGCMX"|awk'{print$(2)}'|awk -F"."'{print$1}'), get the maximum Perm area size defined by the JVM;
[0144] Then, through the jstat command: v_used = $(jstat-gc${v_pid}|grep-v"PU"|awk'{print$(NF-5)}'|awk-F"."'{print$1}'), we can get the current Perm area usage size; similarly, through the jstat command: v_max_meta_size = $(jstat-gcmetacapacity${v_pid}|grep-v"MCMX"|awk'{print$(2)}'|awk-F"."'{print$1}'), we can get the maximum MetaSpace area size defined by the JVM;
[0145] Then use the jstat command: v_used = $(jstat -gc ${v_pid} | grep -v "MU" | awk '{print $(NF-7)}' | awk -F "." '{print $1}') to get the current MetaSpace area usage size;
[0146] Similarly, through the jstat command: v_max_old_size = $(jstat -gc ${v_pid} | grep -v "PU" | awk '{print $(7)}' | awk -F "." '{print $1}'), the size of the Old area can be obtained;
[0147] Then use the jstat command: v_used = $(jstat -gc ${v_pid} | grep -v "PU" | awk '{print $(8)}' | awk -F "." '{print $1}') to get the current size of the Old area.
[0148] A perm zone usage rate of the perm zone is calculated based on the perm zone size and the perm zone usage size.
[0149] The Perm usage rate is calculated by v_ratio=$(echo "100*${v_used} / ${v_max_perm_size} / 1024"|bc).
[0150] If Perm usage is ≥ 95%, a major warning is issued, and if Perm usage is ≥ 85%, a minor warning is issued.
[0151] Based on the MetaSpace area size and the MetaSpace area usage size, a MetaSpace area usage rate of the MetaSpace area is calculated.
[0152] The MetaSpace area usage rate is calculated by v_ratio=$(echo "100*${v_used} / ${v_max_meta_size} / 1024"|bc).
[0153] If the MetaSpace area usage is greater than or equal to 95%, a major warning is issued, and if the MetaSpace area usage is greater than or equal to 85%, a minor warning is issued.
[0154] Based on the Old area size and the Old area usage size, an Old area usage rate of the Old area is calculated.
[0155] The usage rate of the Old area is calculated by v_ratio=$(echo "100*${v_used} / ${v_max_old_size} / 1024"|bc).
[0156] If the Old area usage is greater than or equal to 95%, a minor warning is issued.
[0157] S306: Obtain the maximum number of files that can be opened by the Java process and the number of currently opened file handles.
[0158] Specifically, you can use / proc / <pid> / limits to obtain the maximum number of file handles that the Java process can open. The specific command is: v_max_open_files = $(grep "Max open files" / proc / ${v_pid} / limits|awk'{print$4}'); through / proc / <pid> / fd obtains the number of file handles currently opened by the Java process. The specific command is: v_open_files=$(ls / proc / ${v_pid} / fd|wc -l).
[0159] S307: Calculate the usage rate of the open file handles based on the maximum number of open file handles of the Java process and the current number of open file handles.
[0160] Based on the maximum number of open file handles v_max_open_files and the current number of open file handles v_open_files obtained above, the usage ratio of open file handles v_open_file_ratio is calculated. The command is:
[0161] v_open_file_ratio=$(echo "${v_open_files}*100 / ${v_max_open_files}"|bc).
[0162] By supplementing and improving relevant monitoring indicators such as FullGC, the number of open file handles of the process, and the usage rate of Perm / MetaSpace and monitoring them effectively, it is possible to ensure that relevant risks are discovered and related problems are solved in a timely manner during the operation phase, thereby improving the completeness of Java monitoring.
[0163] In the embodiment provided by the present invention, optionally, the obtaining of FullGC monitoring indicators within a preset time period based on the GC log includes:
[0164] The GC log output path of the JVM instance is obtained, and the GC log is obtained based on the GC log output path.
[0165] Through the third keyword contained in the above process information, that is, the Xloggc keyword, the GC log output path of the JVM instance can be extracted, and the corresponding GC log can be obtained according to the obtained GC log output path.
[0166] The last scan position recorded in the GC log is determined, and the GC log is scanned with the last scan position as a starting position to obtain log content of the GC log within the preset time period.
[0167] After each monitoring check is completed, the last position of the GC log scanned by the monitoring check is recorded. When checking within the preset time period, the last position of the previous scan is recorded and used as the initial position to scan the GC log to read the log content within the preset time period. If the last position of the previous scan is not obtained, such as the first monitoring check, the last position of the previous scan is assumed to be the last line of the GC log.
[0168] The GC log content is analyzed to obtain the FullGC monitoring index within the preset time period.
[0169] Take the preset time period as the inspection period, analyze the GC log content within the inspection period, and obtain the FullGC monitoring indicators of the inspection period. Specifically:
[0170] Count the number of FullGC occurrences during the inspection cycle and obtain the number of FullGCs.
[0171] The time consumed by each FullGC in the inspection cycle is accumulated to obtain the total time consumed by FullGC.
[0172] The average FullGC duration is obtained by dividing the total FullGC duration by the number of FullGCs.
[0173] Read the last line of FullGC log within the scan range, extract the actual Heap size and the Heap usage size after FullGC from the log, and calculate the Heap usage rate after FullGC. The calculation formula is FullGC Heap recovery rate = (Heap usage size before FullGC - Heap usage size after FullGC) / (actual Heap size). The FullGC Heap recovery rate is used to evaluate whether FullGC can effectively recover Heap. Based on the calculated data, determine whether there is an abnormality in the monitoring data file. If there is an abnormality, issue a corresponding alarm message.
[0174] For example, if the monitoring collection script is executed every 2 minutes by default, a major warning will be issued if the number of FullGCs during the inspection period is greater than or equal to 10, and a minor warning will be issued if it is greater than or equal to 5; a major warning will be issued if the average FullGC duration is greater than or equal to 8, and a minor warning will be issued if it is greater than or equal to 4; a major warning will be issued if the total FullGC duration is greater than or equal to 20, and a minor warning will be issued if it is greater than or equal to 10; a major warning will be issued if the Heap usage rate after FullGC is greater than or equal to 95, and a minor warning will be issued if it is greater than or equal to 90; a major warning will be issued if the FullGC Heap recovery rate is less than or equal to 2, and a minor warning will be issued if it is less than or equal to 5.
[0175] The GC log is obtained through the GC log output path, and the last scan position recorded in the GC log is recorded, and the GC log is scanned from the last scan position as the starting position, so as to obtain the log content of the GC log within the preset time period, and the log content is analyzed to obtain the FullGC monitoring indicators within the preset time period.
[0176] In the embodiment provided by the present invention, optionally, determining the FullGC monitoring index within the preset time period based on the FullGC monitoring index information contained in the preset temporary file includes:
[0177] Obtain the historical FullGC monitoring indicators recorded when each monitoring indicator corresponding to the monitoring object was collected last time and contained in the temporary file;
[0178] Specifically, get the last recorded FullGC number local v_gc_count_last. The specific command is: local v_gc_count_last = $(grep -w "${v_pid}" ${V_JSTAT_TMP_FILE} | awk -F "|" '{print$2}' | head -n 1);
[0179] Get the total time consumed by the last FullGC recorded, local v_gc_time_last. The specific command is: local v_gc_time_last = $(grep -w "${v_pid}" ${V_JSTAT_TMP_FILE} | awk -F "|" '{print$3}' | head -n 1).
[0180] A current FullGC monitoring index corresponding to the monitoring object is determined, and based on the current FullGC monitoring index and the historical FullGC monitoring index, a FullGC monitoring index within the preset time period is calculated.
[0181] Specifically, get the current FullGC number local v_gc_count_now. The specific command is: local v_gc_count_now=$(jstat -gc${v_pid}|grep -v "MU"|awk'{print$(NF-2)}'|awk -F"."'{print$1}');
[0182] Get the current FullGC number local v_gc_time_now. The specific command is: local v_gc_time_now = $(jstat -gc${v_pid}|awk'{print$(NF-1)}'|awk -F"."'{print$1}');
[0183] The number of FullGC times within the time interval is calculated by local v_fullgc_count = $(echo
[0184] "${v_gc_count_now}-${v_gc_count_last}"|bc)local v_fullgc_count;
[0185] The total FullGC time consumed in the time interval is obtained by calculating local v_fullgc_totaltime=$(echo "${v_gc_time_now}-${v_gc_time_last}"|bc);
[0186] Finally, the average FullGC time consumption v_fullgc_avgtime = $(echo
[0187] "${v_fullgc_totaltime} / ${v_fullgc_count}"|bc).
[0188] like Figure 4 As shown, in a specific embodiment provided by the present invention, when monitoring various Java applications, first, the monitoring script is scheduled to be executed in the server to be monitored, and the monitoring script can be executed once every 5 minutes by default to obtain various Java processes running in the server to form a Java process list. Each Java process is a JVM instance, corresponding to a monitoring object. If there is a Java process on the server, the name of the monitoring object corresponding to each Java process is defined according to the Java process to avoid the change of the monitoring object name after the Java process is restarted. Specifically, the monitoring object name can be defined according to the <application type>: <instance name> rule or through the monitoring port. After clarifying the monitoring object name, the operating indicators of the monitoring object are further collected. The monitoring indicators mainly include: FullGC, Heap usage, and the number of open file handles. And the collected monitoring indicators are formatted and output to the specified monitoring indicator data file according to the specification requirements, so that the monitoring tool can scan the monitoring indicator data file, collect each formatted monitoring indicator data to the monitoring platform, and the monitoring tool processes the collected monitoring indicator data, including calculating each monitoring indicator data, and displaying each monitoring indicator data, and at the same time judging whether there is abnormal monitoring indicator data. If there is an abnormality, an alarm notification is generated.
[0189] The specific implementation processes and derivative methods of the above-mentioned embodiments are all within the protection scope of the present invention.
[0190] and Figure 1 Corresponding to the method described above, the embodiment of the present invention further provides a Java application monitoring device for monitoring Figure 1 The specific implementation of the method in the embodiment of the present invention is that the Java application monitoring device provided by the embodiment of the present invention can be applied to a computer terminal or various mobile devices, and its structural diagram is as follows Figure 5 As shown, specifically including:
[0191] A starting unit 501 is used to start a preset monitoring collection script according to a preset time period;
[0192] The first collection unit 502 is used to collect the Java process of the preset server by applying the monitoring collection script;
[0193] A setting unit 503 is used to determine a monitoring object corresponding to the Java process and set a monitoring object name corresponding to the monitoring object;
[0194] The second collection unit 504 is used to collect various monitoring indicators corresponding to the monitoring object, and output monitoring data files corresponding to each monitoring indicator to a preset monitoring tool;
[0195] The processing unit 505 is used to apply the monitoring tool to perform data processing on the monitoring data file to obtain a processed monitoring data file;
[0196] A judging unit 506, configured to judge whether the monitoring data file has an abnormality based on a preset monitoring rule;
[0197] The alarm unit 507 is used to issue an alarm notification corresponding to the monitored object if there is an abnormality in the monitoring data file.
[0198] Based on the Java application monitoring device provided by the present invention, during the Java application monitoring process, the starting unit starts the preset monitoring collection script according to the preset time period, the first collection unit uses the monitoring collection script to collect the currently effectively running Java process; the setting unit determines the monitoring object corresponding to the Java process, and sets the monitoring object name of the monitoring object; the second collection unit collects each monitoring indicator corresponding to the monitoring object, and outputs the monitoring data file corresponding to each monitoring indicator to the preset monitoring tool; the processing unit uses the monitoring tool to perform data processing on the monitoring data file to obtain the processed monitoring data file; based on the preset monitoring rules, the judgment unit judges whether there is an abnormality in the monitoring data file; if there is an abnormality in the monitoring data file, the alarm unit issues an alarm notification corresponding to the monitoring object.
[0199] By using the device provided by the present invention, various Java processes currently running effectively are collected through monitoring and collection scripts, and various monitoring indicators of the monitoring objects corresponding to each Java process are collected. The monitoring tool is used to process the collected monitoring indicators to realize monitoring of various Java applications, thereby ensuring the operation security of Java applications and products.
[0200] For the specific working process of each unit and sub-unit in the Java application monitoring device disclosed in the above embodiment of the present invention, reference may be made to the corresponding content in the Java application monitoring method disclosed in the above embodiment of the present invention, and will not be repeated here.
[0201] An embodiment of the present invention further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned Java application monitoring method.
[0202] The embodiment of the present invention further provides an electronic device, the structural diagram of which is shown in FIG. Figure 6 As shown, it specifically includes a memory 601 and one or more instructions 602, wherein the one or more instructions 602 are stored in the memory 601 and are configured to be executed by one or more processors 603 to perform the following operations:
[0203] Start the preset monitoring collection script according to the preset time period;
[0204] Apply the monitoring and collection script to collect the currently running Java processes;
[0205] Determine the monitoring object corresponding to the Java process, and set the monitoring object name of the monitoring object;
[0206] Collecting various monitoring indicators corresponding to the monitoring object, and outputting monitoring data files corresponding to each monitoring indicator to a preset monitoring tool;
[0207] Using the monitoring tool to process the monitoring data file to obtain a processed monitoring data file;
[0208] Based on preset monitoring rules, determine whether the monitoring data file has any abnormality;
[0209] If there is an abnormality in the monitoring data file, an alarm notification corresponding to the monitoring object is issued.
[0210] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0211] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, computer software, or a combination of both.
[0212] In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0213] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.< / pid> < / pid>
Claims
1. A Java application monitoring method, characterized in that: include: Start the preset monitoring collection script according to the preset time period; Apply the monitoring and collection script to collect the currently running Java processes; Determine the monitoring object corresponding to the Java process, and set the monitoring object name of the monitoring object; Collecting various monitoring indicators corresponding to the monitoring object, and outputting monitoring data files corresponding to each monitoring indicator to a preset monitoring tool; Using the monitoring tool to process the monitoring data file to obtain a processed monitoring data file; Based on preset monitoring rules, determine whether the monitoring data file has any abnormality; If there is an abnormality in the monitoring data file, an alarm notification corresponding to the monitoring object is issued; The collecting of each monitoring indicator corresponding to the monitoring object includes: obtaining a third keyword contained in the process information, the third keyword being a log keyword for determining whether there is a GC log; based on the third keyword, determining whether there is a GC log of the JVM instance corresponding to the Java process; if there is a GC log of the JVM instance corresponding to the Java process, obtaining the FullGC monitoring indicator within a preset time period based on the GC log; the FullGC monitoring indicator includes the number of FullGC times, the average FullGC time consumption, the total FullGC time consumption, the Heap usage rate after FullGC, and the Heap recovery rate after FullGC; if there is no The GC log of the JVM instance corresponding to the Java process determines the FullGC monitoring index within the preset time period based on the FullGC monitoring index information contained in the preset temporary file; applies the preset jstat command to obtain the Heap monitoring index of the Heap, where the Heap is the heap memory of the Java process, and the Heap monitoring index includes the Perm usage rate, the MetaSpace usage rate and the Old usage rate; obtains the maximum number of openable files and the currently open file handles of the Java process; calculates the usage rate of the open file handles based on the maximum number of openable file handles and the currently open file handles of the Java process.
2. The method according to claim 1, characterized in that The application of the monitoring collection script to collect the currently running Java processes includes: Obtaining preset process information, and extracting a first keyword contained in the process information; Acquire a preset process list based on the first keyword, and detect whether the process list includes at least one Java process; When the process list includes at least one Java process, obtaining a preset blacklist; Based on the blacklist, valid Java processes in the process list are determined, and the monitoring collection script is applied to collect valid Java processes in the process list.
3. The method according to claim 2, characterized in that The step of setting the monitoring object name of the monitoring object includes: Based on the first keyword, determining an application type of a monitoring object corresponding to the Java process; Extracting instance information of the application type; When the instance information of the application type is successfully extracted, obtaining at least one second keyword from the instance information, and forming an instance name by each of the second keywords, wherein the second keyword is an instance keyword of the JVM instance corresponding to the Java process; Based on the application type and the instance name, a monitoring object name corresponding to the monitoring object is formed; When extracting the instance information of the application type fails, obtaining port information of a monitoring port for monitoring the Java process; Based on the application type and the port information, a monitoring object name corresponding to the monitoring object is constructed.
4. The method according to claim 1, characterized in that: The obtaining of FullGC monitoring indicators within a preset time period based on the GC log includes: Obtaining a GC log output path of the JVM instance, and obtaining a GC log based on the GC log output path; Determine the last scan position recorded in the GC log, scan the GC log with the last scan position as the starting position, and obtain the log content of the GC log within the preset time period; The GC log content is analyzed to obtain the FullGC monitoring index within the preset time period.
5. The method according to claim 1, characterized in that The determining of the FullGC monitoring index within the preset time period based on the FullGC monitoring index information contained in the preset temporary file includes: Obtain the historical FullGC monitoring indicators recorded when each monitoring indicator corresponding to the monitoring object was collected last time and contained in the temporary file; A current FullGC monitoring index corresponding to the monitoring object is determined, and based on the current FullGC monitoring index and the historical FullGC monitoring index, a FullGC monitoring index within the preset time period is calculated.
6. The method according to claim 1, characterized in that The application uses the preset jstat command to obtain the Heap monitoring indicators of the Heap, including: Determine the perm area size and the used size of the perm area of the largest perm area, the MetaSpace area size and the used size of the MetaSpace area of the largest MetaSpace area, and the Old area size and the used size of the Old area of the largest Old area in the JVM instance; Calculating a perm zone usage rate of the perm zone based on the perm zone size and the perm zone usage size; Calculate the MetaSpace zone usage rate of the MetaSpace zone based on the MetaSpace zone size and the MetaSpace zone usage size; Based on the Old area size and the Old area usage size, an Old area usage rate of the Old area is calculated.
7. A Java application monitoring device, characterized in that: include: A startup unit, used to start a preset monitoring collection script according to a preset time period; A first collection unit, used to collect a Java process of a preset server by applying the monitoring collection script; A setting unit, used to determine a monitoring object corresponding to the Java process, and set a monitoring object name corresponding to the monitoring object; A second collection unit, used to collect various monitoring indicators corresponding to the monitoring object, and output monitoring data files corresponding to each of the monitoring indicators to a preset monitoring tool; A processing unit, configured to use the monitoring tool to perform data processing on the monitoring data file to obtain a processed monitoring data file; A judging unit, configured to judge whether the monitoring data file has an abnormality based on a preset monitoring rule; An alarm unit, configured to issue an alarm notification corresponding to the monitored object if there is an abnormality in the monitoring data file; The collecting of each monitoring indicator corresponding to the monitoring object includes: obtaining a third keyword contained in the process information, the third keyword being a log keyword for determining whether there is a GC log; based on the third keyword, determining whether there is a GC log of the JVM instance corresponding to the Java process; if there is a GC log of the JVM instance corresponding to the Java process, obtaining the FullGC monitoring indicator within a preset time period based on the GC log; the FullGC monitoring indicator includes the number of FullGC times, the average FullGC time consumption, the total FullGC time consumption, the Heap usage rate after FullGC, and the Heap recovery rate after FullGC; if there is no The GC log of the JVM instance corresponding to the Java process determines the FullGC monitoring index within the preset time period based on the FullGC monitoring index information contained in the preset temporary file; applies the preset jstat command to obtain the Heap monitoring index of the Heap, where the Heap is the heap memory of the Java process, and the Heap monitoring index includes the Perm usage rate, the MetaSpace usage rate and the Old usage rate; obtains the maximum number of openable files and the currently open file handles of the Java process; calculates the usage rate of the open file handles based on the maximum number of openable file handles and the currently open file handles of the Java process.
8. A storage medium comprising stored instructions, wherein: When the instruction is executed, the device where the storage medium is located is controlled to execute the Java application monitoring method according to any one of claims 1 to 6.
9. An electronic device comprising a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the Java application monitoring method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Server, method for monitoring Java process, and storage medium
CN108874624A