Configurable non-intrusive Java application memory snapshot automatic generation method
By generating JVM memory snapshots through flexible rule injection using Java Agent, the need for automated operation and maintenance of large-scale clusters is addressed. This enables accurate detection of memory leaks and secure protection of resources, adapts to changes in business load, and avoids accidental triggering and resource exhaustion.
Patent Information
- Application Number
- CN202510857481.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-25
- Publication Date
- 2025-11-21
AI Technical Summary
Existing methods for generating JVM heap memory snapshots cannot meet the needs of automated operation and maintenance of large-scale clusters, are difficult to dynamically adapt to changes in business load, leading to false triggers or missed reports, and pose risks of high intrusion and resource exhaustion.
Using a Java Agent as the carrier, configurable and flexible rules are injected to form scenario-based triggering strategies by combining data. Through file path checks and operation circuit breaking mechanisms, accurate generation and security protection of JVM memory snapshots are achieved.
It implements dynamic adjustment of memory snapshot policies, improves the accuracy of memory leak detection, prevents resource exhaustion, enhances fault predictability and security, and complies with enterprise-level security standards.
Smart Images

Figure CN120994426A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Java application memory monitoring and automated operation and maintenance technology, and more specifically, to a configurable, non-intrusive method for automatically generating Java application memory snapshots. Background Technology
[0002] Existing technical solutions for generating JVM heap memory snapshots: 1. Manual triggering: Traditional tools (such as jmap and JConsole) are used for manual intervention. When a problem occurs in the target application, the JDK's built-in tools are used to generate a memory snapshot via command line in the console. Since current deployments are mostly large-scale microservice clusters, this manual approach results in a significant workload for manual operations and maintenance, and cannot meet the automated operation and maintenance needs of large-scale clusters.
[0003] 2. Two methods are employed: direct code modification and fixed startup parameter modification, embedding monitoring code and parameters. This method requires adaptation modifications to the target system's code, pre-setting static thresholds in the code and parameters, and generating a heap memory snapshot through a threshold-triggered mechanism (e.g., when heap memory reaches 80%). This method is highly invasive and difficult to dynamically adapt to changes in business load (e.g., sudden traffic surges), potentially leading to false triggers or missed alerts. Furthermore, this method is susceptible to illegal file access and resource exhaustion. Summary of the Invention
[0004] This invention addresses the problems of existing methods for generating JVM heap memory snapshots, which are unable to meet the automated operation and maintenance needs of large-scale clusters and are difficult to dynamically adapt to changes in business load, leading to false triggering or missed reports. It proposes a configurable and non-intrusive method for automatically generating Java application memory snapshots. Using a Java Agent as a carrier, it injects configurable and flexible rules and uses combined data to form a scenario-based triggering strategy, enabling more accurate generation of JVM memory snapshots. Furthermore, it prevents abnormal situations such as illegal file access and resource exhaustion by checking the generated file path and implementing an operation circuit breaker mechanism.
[0005] The specific implementation details of this invention are as follows: A configurable, non-intrusive method for automatically generating Java application memory snapshots includes the following steps: Step S1: Create a utility class and generate the obtained memory snapshot to the specified path based on the utility class; Step S2: Based on the acquired basic indicators, construct a set of basic indicators and create an indicator collection tool class; Step S3: Based on the indicator collection tool class, obtain the current basic indicator value, calculate the composite indicator value that triggers the generation of memory snapshot, and create a rule trigger engine; Step S4: Create a rule dynamic loading listener, and use the set rule combination judgment logic to determine whether the rule is hit; Step S5: If the rule is hit, perform a safety count and judgment, and perform a path check to determine whether it meets the safety check requirements; Step S6: If the requirements are met, create a snapshot generation probe based on Java Agent and generate a heapdump snapshot to the local disk.
[0006] To better realize the present invention, step S1 further includes the following steps: Step S11: Call ManagementFactory to create a utility class, and generate a heap dump file based on the created utility class; Step S12: Based on the utility class, call the dumpHeap method to generate the obtained memory snapshot to the specified path.
[0007] To better realize the present invention, step S2 further includes the following steps: Step S21: Construct a set of basic indicators based on the acquired basic indicators; The basic metrics include JVM Heap utilization, Old Gen utilization, Metaspace occupancy, and Full GC count; Step S22: Create an indicator collection tool class based on the basic indicator set.
[0008] To better realize the present invention, step S22 further includes the following steps: Step S221: Call the ManagementFactory.getMemoryMXBean() method to create a MemoryMXBean for monitoring memory metrics; call the getHeapMemoryUsage() method to obtain the used and maximum values of Heap memory, and calculate the Heap utilization rate based on the used and maximum values; Step S222: Call the ManagementFactory.getMemoryPoolMXBeans().stream() method to obtain the corresponding name of G1 according to the GC algorithm, filter and obtain the MemoryPoolMXBeans with Old Gen and Metaspace metrics, and calculate the Old Gen utilization rate and Metaspace occupancy ratio by using the used value and the maximum value. Step S223: Call the ManagementFactory.getGarbageCollectorMXBeans().stream() method to create a GarbageCollectorMXBean stream, and calculate getCollectionCount based on the GarbageCollectorMXBean stream to count the number of Full GCs.
[0009] To better realize the present invention, step S3 further includes the following steps: Step S31: Obtain the current basic indicator value according to the indicator collection tool class, and calculate the values of each composite indicator used to trigger the generation of memory snapshot; Step S32: Based on the composite index value, check the size of each threshold scalar and index value, return true and false results, and create a rule triggering engine.
[0010] To better realize the present invention, step S31 further includes the following steps: Step S311: According to the set collection period, call the sliding window to subtract the current Old Gen utilization rate value from the earliest saved Old Gen utilization rate value, and then divide by the earliest saved Old Gen utilization rate value to obtain the final value, which is used as the Old Gen growth rate. Step S312: Subtract the previously saved Full GC count from the current Full GC count to obtain the final Full GC count difference. Then replace the previously saved Full GC count with the current Full GC count for the next calculation, which will be used as the Full GC frequency.
[0011] To better implement the present invention, the specific operation of step S32 is as follows: a rule combination judgment logic group is built into the rule triggering engine, and the rule combination is performed according to different parameters. Each combination forms a rule node. During runtime, the responsibility chain mode is called to judge the rule nodes in turn according to the actual indicator parameters obtained. Then, the rule result that is hit first is returned according to the rule priority. If none of them are hit, it is considered that the rule triggering condition is not met.
[0012] To better realize the present invention, step S4 further includes the following steps: Step S41: Call NacosFactory.createConfigService to create the Nacos client configuration, and register the listener using configService.addListener; Step S42: Call ScheduledExecutorService to create a listening thread, initialize the Nacos client configuration based on the obtained Nacos server address information, and start the listening scheduling task; Step S43: Parse the configuration parameters and pass the corresponding values as thresholds into the rule triggering engine. After the triggering engine makes a judgment, it calls the heap dump generation utility class to create a configuration file in the external configuration center Nacos and set the thresholds for each indicator.
[0013] To better realize the present invention, step S5 further includes the following steps: Step S51: Call the atomic operation class AtomicInteger to clear the value after each heap dump generation operation is completed. If the operation is not completed or an operation exception occurs, increment the value by 1. When the cumulative number of operations exceeds 3, trigger the circuit breaker to prevent further heap dump operations and avoid exhausting thread and memory resources. Use Files.getFileStore to get the remaining disk space. If the disk space is less than the minimum required for heap dump generation, do not generate a heap dump file.
[0014] To better implement the present invention, step S6 is further defined as follows: calling Instrumentation to create a dynamic proxy class and implementing the Agent entry method premain; generating a heapdump snapshot to the local disk.
[0015] The present invention has the following beneficial effects: (1) The present invention realizes real-time threshold updates through the configuration center, meets the requirements of different business scenarios for heapdump generation, and realizes dynamic strategy adjustment.
[0016] (2) The multi-dimensional joint rule judgment of this invention improves the accuracy of memory leak detection. The composite judgment model can detect potential memory leaks 20-30 minutes in advance, which improves fault prediction compared with the traditional OOM post-analysis mode and achieves accurate fault capture. (3) This invention enhances security by employing a circuit breaker mechanism to prevent frequent heap dump operations and the exhaustion of thread and memory resources. It dynamically adjusts the circuit breaker counter reset strategy based on historical operation success rates and system load, automatically restoring some heap dump sampling capabilities during off-peak periods. Multi-dimensional resource linkage protection is also implemented: when GC time exceeds a safety threshold, the thread pool is fully loaded, or disk space is insufficient, heap dump generation is automatically paused. A path verification mechanism prevents illegal file access, complying with enterprise-level security standards. Attached Figure Description
[0017] Figure 1 The system architecture diagram provided for this invention.
[0018] Figure 2 A flowchart provided for this invention. Detailed Implementation
[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments, and therefore should not be regarded as a limitation on the scope of protection. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "set up," "connected," and "linked" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0021] Example 1: This embodiment presents a configurable, non-intrusive method for automatically generating Java application memory snapshots, which specifically includes the following steps: Step S1: Create a utility class and generate the obtained memory snapshot to the specified path based on the utility class; Step S1 specifically includes the following steps: Step S11: Call ManagementFactory to create a utility class, and generate a heap dump file based on the created utility class; Step S12: Based on the utility class, call the dumpHeap method to generate the obtained memory snapshot to the specified path.
[0022] Step S2: Based on the acquired basic indicators, construct a set of basic indicators and create an indicator collection tool class; Step S2 specifically includes the following steps: Step S21: Construct a set of basic indicators based on the acquired basic indicators; The basic metrics include JVM Heap utilization, Old Gen utilization, Metaspace occupancy, and Full GC count; Step S22: Create an indicator collection tool class based on the basic indicator set.
[0023] Step S22 specifically includes the following steps: Step S221: Call the ManagementFactory.getMemoryMXBean() method to create a MemoryMXBean for monitoring memory metrics; call the getHeapMemoryUsage() method to obtain the used and maximum values of Heap memory, and calculate the Heap utilization rate based on the used and maximum values; Step S222: Call the ManagementFactory.getMemoryPoolMXBeans().stream() method to obtain the corresponding name of G1 according to the GC algorithm, filter and obtain the MemoryPoolMXBeans with Old Gen and Metaspace metrics, and calculate the Old Gen utilization rate and Metaspace occupancy ratio by using the used value and the maximum value. Step S223: Call the ManagementFactory.getGarbageCollectorMXBeans().stream() method to create a GarbageCollectorMXBean stream, and calculate getCollectionCount based on the GarbageCollectorMXBean stream to count the number of Full GCs.
[0024] Step S3: Based on the indicator collection tool class, obtain the current basic indicator value, calculate the composite indicator value that triggers the generation of memory snapshot, and create a rule trigger engine.
[0025] Step S3 specifically includes the following steps: Step S31: Obtain the current basic indicator value according to the indicator collection tool class, and calculate the values of each composite indicator used to trigger the generation of memory snapshot; Step S31 specifically includes the following steps: Step S311: According to the set collection period, call the sliding window to subtract the current Old Gen utilization rate value from the earliest saved Old Gen utilization rate value, and then divide by the earliest saved Old Gen utilization rate value to obtain the final value, which is used as the Old Gen growth rate. Step S312: Subtract the previously saved Full GC count from the current Full GC count to obtain the final Full GC count difference. Then replace the previously saved Full GC count with the current Full GC count for the next calculation, which will be used as the Full GC frequency.
[0026] Step S32: Based on the composite index value, check the size of each threshold scalar and index value, return true and false results, and create a rule triggering engine.
[0027] The specific operation of step S32 is as follows: a rule combination judgment logic group is built into the rule triggering engine. The rule combination is performed according to different parameters. Each combination forms a rule node. During runtime, the chain of responsibility mode is called to judge the rule nodes in turn according to the actual indicator parameters obtained. Then, the rule result that is hit first is returned according to the rule priority. If none of them are hit, it is considered that the rule triggering condition is not met.
[0028] Step S4: Create a rule dynamic loading listener, and use the set rule combination judgment logic to determine whether the rule is hit; Step S4 specifically includes the following steps: Step S41: Call NacosFactory.createConfigService to create the Nacos client configuration, and register the listener using configService.addListener; Step S42: Call ScheduledExecutorService to create a listening thread, initialize the Nacos client configuration based on the obtained Nacos server address information, and start the listening scheduling task; Step S43: Parse the configuration parameters and pass the corresponding values as thresholds into the rule triggering engine. After the triggering engine makes a judgment, it calls the heap dump generation utility class to create a configuration file in the external configuration center Nacos and set the thresholds for each indicator.
[0029] Step S5: If the rule is hit, perform a safety count and judgment, and perform a path check to determine whether it meets the safety check requirements; Step S5 specifically includes the following steps: Step S51: Call the atomic operation class AtomicInteger to clear the value after each heap dump generation operation is completed. If the operation is not completed or an operation exception occurs, increment the value by 1. When the cumulative number of operations exceeds 3, trigger the circuit breaker to prevent further heap dump operations and avoid exhausting thread and memory resources. Use Files.getFileStore to get the remaining disk space. If the disk space is less than the minimum required for heap dump generation, do not generate a heap dump file.
[0030] Step S6: If the requirements are met, create a snapshot generation probe based on Java Agent and generate a heapdump snapshot to the local disk.
[0031] The specific operation of step S6 is as follows: call Instrumentation to create a dynamic proxy class and implement the Agent entry method premain; generate a heapdump snapshot to the local disk.
[0032] Working principle: This embodiment uses a Java Agent as a carrier to inject configurable and flexible rules and combine data to form a scenario-based triggering strategy, so as to generate JVM memory snapshots more accurately, and prevent illegal file access and resource exhaustion through file path checking and operation circuit breaking mechanism.
[0033] Example 2: This embodiment is based on the above embodiment 1, such as... Figure 1 , Figure 2 As shown, a specific embodiment will be used for illustration.
[0034] This embodiment uses a Java Agent as a carrier to inject configurable and flexible rules and combine data to form a scenario-based triggering strategy, thereby achieving more accurate generation of JVM memory snapshots. It also prevents illegal file access and resource exhaustion by generating file path checks and operation circuit breaking mechanisms.
[0035] The specific steps are as follows: Step S1: First, determine the JVM version, which must be greater than or equal to 8.0. Then, use ManagementFactory to create a utility class for generating heap dump files. This utility class mainly uses HotSpotDiagnosticMXBean to provide the method dumpHeap(String outputFile, boolean live) to generate a real-time memory snapshot to the specified path.
[0036] Step S2: Determine the indicator system, i.e., the set of basic indicators used for rule configuration. In this embodiment, the basic indicators used include JVM Heap utilization, Old Gen utilization, Metaspace occupancy ratio, and Full GC count as the basic indicators for rule configuration. Then, create an indicator collection utility class. This mainly uses `ManagementFactory.getMemoryMXBean()` to create `MemoryMXBean`s for monitoring memory indicators. It obtains the used and maximum values of Heap memory by calling the `getHeapMemoryUsage()` method, and calculates the Heap utilization based on these values. It also uses `ManagementFactory.getMemoryPoolMXBeans().stream()` to obtain `MemoryPoolMXBean`s for Old Gen and Metaspace indicators based on the specific GC algorithm (e.g., filtering by the corresponding name for G1), and calculates the Old Gen utilization and Metaspace occupancy ratio based on the used and maximum values. Finally, it uses `ManagementFactory.getGarbageCollectorMXBeans().stream()` to create a `GarbageCollectorMXBean` stream, and calculates `getCollectionCount` through the stream to count the number of Full GCs.
[0037] Step S3: Rule Triggering Engine. Create a rule triggering engine. Using the metric collection utility class from Step S2, obtain the current basic metric values, calculate the composite metric values used to trigger the generation of memory snapshots, and then check the size of each threshold scalar and metric value. The method is as follows: Use the Old Gen growth rate and Full GC frequency as composite metrics. The Old Gen growth rate algorithm uses a sliding window calculation, saving the most recent 60 time points (assuming collection per second). Subtract the earliest saved value from the current value and divide by the earliest saved value to obtain the final value. The Full GC frequency algorithm subtracts the previously saved value from the current value, obtaining the difference as the final value, and then replaces the previously saved value with the current value for the next calculation.
[0038] The rule triggering engine has a built-in rule combination judgment logic group. It combines rules according to different parameters, and each combination forms a rule node. At runtime, the rule nodes are judged sequentially through the chain of responsibility mode based on the actual indicator parameters obtained. Then, the result of the hit rule is returned according to the rule priority. If none of them are hit, the result of the hit rule is returned, indicating that the rule triggering conditions are not met.
[0039] For example: A rule is as follows, which checks the status of various indicators: If the Heap usage rate is greater than or equal to a set threshold (e.g., 85%), and if the Old Gen growth rate is greater than or equal to a set threshold (e.g., 15%), generation will be triggered. Alternatively, if the Metaspace usage is greater than or equal to the set threshold (e.g., 90%), and if the number of Full GCs / 30 seconds is greater than or equal to the set threshold (e.g., 5 times), a generation will be triggered.
[0040] Record the timestamp of the last dump. If the time remaining from the current time is less than the cooldown period (e.g., 10 minutes), skip the trigger to avoid duplicate data collection.
[0041] Step S4: Dynamic Rule Configuration Change Listener. Create a dynamic rule loading listener. To listen for real-time updates of external rule threshold parameters, a configuration change listener needs to be created. Use `NacosFactory.createConfigService` to create a Nacos client configuration and register a listener using `configService.addListener`. This listener listens for changes to the corresponding server-side configuration data, parses the configuration data in real-time to update local rules, and uses `ScheduledExecutorService` to create a listening thread. It initializes the Nacos client configuration based on subsequently passed Nacos server address information and starts a listening scheduler task every 5 seconds. The configuration parameters are parsed, and the corresponding values are passed as thresholds to the rule triggering engine. The triggering engine then judges the values and calls the heap dump generation utility class. In the external configuration center Nacos, a configuration file is created, setting various metric thresholds, such as: trigger_rules: heap_usage: 0.85 #Heap memory exceeds 85% old_gen_growth: 0.15 #0ldGen's hourly growth rate exceeds 15% metaspace_usage: 0.90 #Metaspace exceeds 90% full_gc_freq: 5 # More than 5 FullGC cycles per minute dump_config: path: " / opt / traces / heapdump_%d{yyyyMMddHHmmss}.hprof" live_mode: true # Whether to only store live objects cooldown: 600 #Minimum trigger interval (seconds) Step S5: Security Enhancer. Create a security enhancement mechanism, including path checking, path replacement, disk space checking, thread pool checking, and operation circuit breaking. This prevents illegal file access in the generated heap dump file and avoids exhausting the host machine's resources during heap dump generation. Specifically, the following methods are used: relative paths are disabled, time variables are replaced to prevent path traversal, and folder name checks are used to restrict generation to specified directories. The AtomicInteger class is used to reset the heap dump generation operation after each operation is completed. If the operation is incomplete or an exception occurs, the value is incremented by 1. When the cumulative count exceeds 3, a circuit breaker is triggered, preventing further heap dump operations and avoiding thread and memory resource exhaustion. Files.getFileStore is used to obtain the remaining disk space; if the disk space required for minimum heap dump generation is not met, a heapdump file is not generated.
[0042] Step S6: Create a snapshot generation probe based on a Java Agent. Use Instrumentation to create a dynamic proxy class, implementing the Agent entry method premain, which includes: parsing JVM startup parameters, initializing the Nacos configuration service, initializing the rule manager, creating a scheduling thread pool, and starting the rule triggering engine.
[0043] Working principle: This embodiment uses a configuration center to update the threshold in real time, which meets the requirements of different business scenarios for heapdump generation. For example, for core transaction services, a lower memory usage threshold (e.g., 80% trigger) and a lower Old Gen growth rate (e.g., 10% trigger) are set, while for batch processing systems, a higher threshold (e.g., 95% trigger) and a higher Full GC frequency (e.g., once / 10 seconds) are used.
[0044] This embodiment improves the accuracy of memory leak detection through multi-dimensional joint rule judgment (compared to single-indicator solutions). For example, it expands from simply monitoring Heap memory usage to a comprehensive analysis of Old Gen growth rate, Full GC frequency, and Heap memory usage. When the Old Gen region continues to grow by more than 5% after three consecutive GCs, a heap dump is still triggered even if the Heap memory has not reached a preset threshold. This composite judgment model can detect potential memory leaks 20-30 minutes in advance, improving fault predictability compared to traditional OOM post-analysis methods.
[0045] This embodiment enhances security by employing a circuit breaker mechanism to prevent frequent heap dump operations and the exhaustion of thread and memory resources. It dynamically adjusts the circuit breaker counter reset strategy based on historical operation success rates and system load, automatically restoring some heap dump sampling capabilities during off-peak periods. Multi-dimensional resource linkage protection is implemented: when GC time exceeds a safe threshold, the thread pool is full, or disk space is insufficient, heap dump generation is automatically paused. A path verification mechanism prevents unauthorized file access, complying with enterprise-level security standards.
[0046] This embodiment sets different triggering rules according to different application scenarios. For example, in the scenario of batch resource cutover service in the telecom operator's resource system, it is configured to trigger the generation of snapshot dump when "heap memory > 85% and Full GC ≥ 3 times within 1 minute". Saving and analyzing the heap dump file in advance can help take corresponding measures to prevent service unavailability. In the peak scenario of resource scheduling configuration, the heap memory combination threshold for triggering snapshot generation is adjusted according to the historical configuration scheduling work order request volume to avoid accidental or frequent snapshot dump generation affecting the performance of core services.
[0047] In this embodiment, on-site data is obtained in advance when deploying in a cloud-native containerized environment: When an application service is deployed using containers, the Pod may be evicted due to an OutOfMemoryError (OOM), which may result in the inability to obtain a memory snapshot file. By using multi-dimensional joint judgment, a snapshot dump can be generated in advance and persisted to object storage to avoid loss of on-site data.
[0048] The other parts of this embodiment are the same as those in Embodiment 1 above, so they will not be described again.
[0049] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Any simple modifications or equivalent changes made to the above embodiments based on the technical essence of the present invention shall fall within the protection scope of the present invention.
Claims
1. A configurable, non-intrusive method for automatically generating memory snapshots of Java applications, characterized in that, Specifically, the following steps are included: Step S1: Create a utility class and generate the obtained memory snapshot to the specified path based on the utility class; Step S2: Based on the acquired basic indicators, construct a set of basic indicators and create an indicator collection tool class; Step S3: Based on the indicator collection tool class, obtain the current basic indicator value, calculate the composite indicator value that triggers the generation of memory snapshot, and create a rule trigger engine; Step S4: Create a rule dynamic loading listener, and use the set rule combination judgment logic to determine whether the rule is hit; Step S5: If the rule is hit, perform a safety count and judgment, and perform a path check to determine whether it meets the safety check requirements; Step S6: If the requirements are met, create a snapshot generation probe based on Java Agent and generate a heapdump snapshot to the local disk.
2. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 1, characterized in that, Step S1 specifically includes the following steps: Step S11: Call ManagementFactory to create a utility class, and generate a heap dump file based on the created utility class; Step S12: Based on the utility class, call the dumpHeap method to generate the obtained memory snapshot to the specified path.
3. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 2, characterized in that, Step S2 specifically includes the following steps: Step S21: Construct a set of basic indicators based on the acquired basic indicators; The basic metrics include JVM Heap utilization, Old Gen utilization, Metaspace occupancy, and Full GC count; Step S22: Create an indicator collection tool class based on the basic indicator set.
4. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 3, characterized in that, Step S22 specifically includes the following steps: Step S221: Call the ManagementFactory.getMemoryMXBean() method to create a MemoryMXBean for monitoring memory metrics; call the getHeapMemoryUsage() method to obtain the used and maximum values of Heap memory, and calculate the Heap utilization rate based on the used and maximum values; Step S222: Call the ManagementFactory.getMemoryPoolMXBeans().stream() method to obtain the corresponding name of G1 according to the GC algorithm, filter and obtain the MemoryPoolMXBeans with Old Gen and Metaspace metrics, and calculate the Old Gen utilization rate and Metaspace occupancy ratio by using the used value and the maximum value. Step S223: Call the ManagementFactory.getGarbageCollectorMXBeans().stream() method to create a GarbageCollectorMXBean stream, and calculate getCollectionCount based on the GarbageCollectorMXBean stream to count the number of Full GCs.
5. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 1, characterized in that, Step S3 specifically includes the following steps: Step S31: Obtain the current basic indicator value according to the indicator collection tool class, and calculate the values of each composite indicator used to trigger the generation of memory snapshot; Step S32: Based on the composite index value, check the size of each threshold scalar and index value, return true and false results, and create a rule triggering engine.
6. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 5, characterized in that, Step S31 specifically includes the following steps: Step S311: According to the set collection period, call the sliding window to subtract the current Old Gen utilization rate value from the earliest saved Old Gen utilization rate value, and then divide by the earliest saved Old Gen utilization rate value to obtain the final value, which is used as the Old Gen growth rate. Step S312: Subtract the previously saved Full GC count from the current Full GC count to obtain the final Full GC count difference. Then replace the previously saved Full GC count with the current Full GC count for the next calculation, which will be used as the Full GC frequency.
7. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 6, characterized in that, The specific operation of step S32 is as follows: a rule combination judgment logic group is built into the rule triggering engine. The rule combination is performed according to different parameters. Each combination forms a rule node. During runtime, the chain of responsibility mode is called to judge the rule nodes in turn according to the actual indicator parameters obtained. Then, the rule result that is hit first is returned according to the rule priority. If none of them are hit, it is considered that the rule triggering condition is not met.
8. The configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 1, characterized in that, Step S4 specifically includes the following steps: Step S41: Call NacosFactory.createConfigService to create the Nacos client configuration, and register the listener using configService.addListener; Step S42: Call ScheduledExecutorService to create a listening thread, initialize the Nacos client configuration based on the obtained Nacos server address information, and start the listening scheduling task; Step S43: Parse the configuration parameters and pass the corresponding values as thresholds into the rule triggering engine. After the triggering engine makes a judgment, it calls the heap dump generation utility class to create a configuration file in the external configuration center Nacos and set the thresholds for each indicator.
9. A configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 8, characterized in that, Step S5 specifically includes the following steps: Step S51: Call the atomic operation class AtomicInteger to clear the value after each heap dump generation operation is completed. If the operation is not completed or an operation exception occurs, increment the value by 1. When the cumulative number of operations exceeds 3, trigger the circuit breaker to prevent further heap dump operations and avoid exhausting thread and memory resources. Use Files.getFileStore to get the remaining disk space. If the disk space is less than the minimum required for heap dump generation, do not generate a heap dump file.
10. A configurable, non-intrusive method for automatically generating Java application memory snapshots according to claim 9, characterized in that, The specific operation of step S6 is as follows: call Instrumentation to create a dynamic proxy class and implement the Agent entry method premain; generate a heapdump snapshot to the local disk.