Virtual machine state monitoring method and device, electronic device and storage medium
By combining a memory monitoring process with an independent monitoring platform, the system automatically detects virtual machine memory usage and total number of threads, enabling virtual machines to self-recover, resolving business interruption issues caused by virtual machine memory overflow, and improving virtual machine availability.
Patent Information
- Application Number
- CN202310583117.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-22
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-05-22
AI Technical Summary
Virtual machines are prone to memory overflow, which can prevent them from handling normal business operations. Existing monitoring systems can only detect high memory usage but cannot automatically recover, thus affecting the availability of virtual machines.
A memory monitoring process is used to detect the memory usage and total number of threads of the virtual machine. The virtual machine is automatically restarted through the monitoring platform. The monitoring platform is deployed independently of the virtual machine, while the memory monitoring process is deployed inside the virtual machine to monitor memory overflow caused by the exhaustion of the number of threads.
It shortened the time for manual monitoring and recovery, improved the availability of virtual machines, increased the coverage of the monitoring and recovery system, and ensured that the original business was not affected.
Smart Images

Figure CN116521322B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of financial technology or other related fields. Specifically, it relates to a virtual machine status monitoring method, apparatus, electronic device, and storage medium. Background Technology
[0002] Memory overflow in computers or virtual machines can cause program crashes, unresponsiveness, and in severe cases, system crashes. Common causes of memory overflow include: 1. Insufficient memory allocation, unable to meet normal business needs; 2. Frequent allocation of an object without release, leading to continuous memory leaks and eventual memory exhaustion; 3. Continuous allocation of a resource, exhausting system resources (e.g., constantly creating threads).
[0003] In related technologies, the main method for solving virtual machine memory overflow problems is to optimize the programs running in the virtual machine to eliminate potential memory leak points. However, since each program's potential memory leak point needs to be analyzed on a case-by-case basis, the technical threshold for elimination is high and the implementation is difficult; moreover, some optimization methods will affect the program's running efficiency; in addition, some existing virtual machine memory overflow monitoring systems can only detect virtual machines with high memory usage and issue alerts, but do not have the function of recovering abnormal virtual machines. The corresponding maintenance personnel can only manually recover after receiving the alert, which is a long and slow process and reduces the availability of virtual machines. At the same time, these monitoring systems only monitor memory usage and cannot detect memory overflow caused by thread exhaustion.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This invention provides a virtual machine status monitoring method, apparatus, electronic device, and storage medium to at least solve the technical problem in related technologies where virtual machines are prone to memory overflow, resulting in the inability to process normal business operations.
[0006] According to one aspect of the present invention, a method for monitoring the state of a virtual machine is provided, comprising: using a memory monitoring process to detect the memory occupancy rate and the total number of threads of the virtual machine, wherein the memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine; using the memory monitoring process to determine the memory state of the virtual machine based on the memory occupancy rate and the total number of threads; and, if the memory state of the virtual machine indicates a memory overflow exception, using the memory monitoring process to send a virtual machine restart request to a monitoring platform, wherein the monitoring platform is deployed independently of each virtual machine, and the monitoring platform interfaces with N memory monitoring processes, where N is an integer greater than or equal to 1.
[0007] Optionally, the step of using a memory monitoring process to detect the memory usage and total number of threads of a virtual machine includes: using the memory monitoring process to count the memory usage at a predetermined interval; and using the memory monitoring process to detect each application process currently in running state at a predetermined interval to obtain the total number of threads.
[0008] Optionally, the step of determining the memory state of the virtual machine based on the memory usage rate and the total number of threads using the memory monitoring process includes: comparing the memory usage rate with a preset usage rate threshold using the memory monitoring process to obtain a memory usage comparison result; incrementing an exception counter by a first specified value when the memory usage comparison result indicates that the memory usage rate is greater than the preset usage rate threshold; comparing the total number of threads with a preset total number threshold using the memory monitoring process to obtain a thread comparison result; incrementing an exception counter by a second specified value when the thread comparison result indicates that the total number of threads is greater than the preset total number threshold; setting the memory state of the virtual machine to memory overflow exception when the accumulated value of the exception counter is greater than a preset exception threshold; and setting the memory state of the virtual machine to normal memory when the accumulated value of the exception counter is less than or equal to the preset exception threshold.
[0009] Optionally, after sending a virtual machine restart request to the monitoring platform using the memory monitoring process, the method further includes: clearing the count value of the exception counter to zero.
[0010] Optionally, the status monitoring method further includes: sending a test command to the memory monitoring process in each of the virtual machines using the monitoring platform, wherein the test command is used to verify whether the memory monitoring process is working normally; when the monitoring platform receives a test failure response or no test response from the memory monitoring process, incrementing the virtual machine counter corresponding to the memory monitoring process by a third specified value; and when the monitoring platform receives a test success response from the memory monitoring process, resetting the count value of the virtual machine counter corresponding to the memory monitoring process to zero.
[0011] Optionally, after incrementing the virtual machine counter corresponding to the memory monitoring process by a third specified value, the method further includes: if the accumulated value of any of the virtual machine counters is greater than a preset counting threshold, sending a restart command to the target virtual machine corresponding to the virtual machine counter using the monitoring platform.
[0012] Optionally, after sending a virtual machine restart request to the monitoring platform using the memory monitoring process, the method further includes: responding to the virtual machine restart request and restarting the virtual machine corresponding to the memory monitoring process through the monitoring platform.
[0013] According to another aspect of the present invention, a virtual machine status monitoring device is also provided, comprising: a detection unit, configured to detect the memory usage rate and total number of threads of a virtual machine using a memory monitoring process, wherein the memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine; a determination unit, configured to determine the memory status of the virtual machine based on the memory usage rate and the total number of threads using the memory monitoring process; and a sending unit, configured to send a virtual machine restart request to a monitoring platform using the memory monitoring process when the memory status of the virtual machine indicates a memory overflow exception, wherein the monitoring platform is deployed independently of each virtual machine, and the monitoring platform interfaces with N memory monitoring processes, where N is an integer greater than or equal to 1.
[0014] Optionally, the detection unit includes: a statistics module, used to use the memory monitoring process to count the memory usage rate at a predetermined interval; and a detection module, used to use the memory monitoring process to detect each application process currently in running state at a predetermined interval to obtain the total number of threads.
[0015] Optionally, the determining unit includes: a first comparison module, used to compare the memory usage rate with a preset usage rate threshold using the memory monitoring process to obtain a memory usage comparison result; a first increment module, used to increment the exception counter by a first specified value when the memory usage comparison result indicates that the memory usage rate is greater than the preset usage rate threshold; a second comparison module, used to compare the total number of threads with a preset total number threshold using the memory monitoring process to obtain a thread comparison result; a second increment module, used to increment the exception counter by a second specified value when the thread comparison result indicates that the total number of threads is greater than the preset total number threshold; a first state setting module, used to set the memory state of the virtual machine to memory overflow exception when the accumulated value of the exception counter is greater than a preset exception threshold; and a second state setting module, used to set the memory state of the virtual machine to memory normal when the accumulated value of the exception counter is less than or equal to a preset exception threshold.
[0016] Optionally, the status monitoring device further includes: a first clearing module, used to clear the count value of the exception counter to zero after the sending unit sends a virtual machine restart request to the monitoring platform using the memory monitoring process.
[0017] Optionally, the status monitoring device further includes: a first sending module, used to send a test command to the memory monitoring process in each of the virtual machines using the monitoring platform, wherein the test command is used to verify whether the memory monitoring process is working normally; a third incrementing module, used to increment the virtual machine counter corresponding to the memory monitoring process by a third specified value when the monitoring platform receives a test failure response or no test response from the memory monitoring process; and a second clearing module, used to clear the count value of the virtual machine counter corresponding to the memory monitoring process to zero when the monitoring platform receives a test normal response from the memory monitoring process.
[0018] Optionally, the status monitoring device further includes: a second sending module, used to send a restart command to the target virtual machine corresponding to the virtual machine counter after the third sending module increments the virtual machine counter corresponding to the memory monitoring process by a third specified value, and if the accumulated value of any of the virtual machine counters is greater than a preset counting threshold, using the monitoring platform.
[0019] Optionally, the status monitoring device further includes a response module, which is used to respond to the virtual machine restart request after the sending unit sends a virtual machine restart request to the monitoring platform using the memory monitoring process, and restart the virtual machine corresponding to the memory monitoring process through the monitoring platform.
[0020] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to execute the virtual machine state monitoring method of any one of the above-mentioned methods.
[0021] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the virtual machine state monitoring method of any one of the above.
[0022] This disclosure proposes a virtual machine status monitoring method. A memory monitoring process is used to detect the memory usage and total number of threads of the virtual machine. The memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine. Based on the memory usage and total number of threads, the memory monitoring process determines the memory status of the virtual machine. When the memory status of the virtual machine indicates a memory overflow exception, the memory monitoring process sends a virtual machine restart request to the monitoring platform. The monitoring platform is deployed independently of each virtual machine and connects to N memory monitoring processes, where N is an integer greater than or equal to 1.
[0023] In this disclosure, a monitoring process is used to monitor the memory usage of virtual machines and provide alerts and self-recovery, which shortens the time for manual monitoring and recovery, improves the availability of virtual machines, and can also perform parallel detection of thread count to monitor memory overflow caused by thread exhaustion, thus increasing the coverage of the monitoring and recovery system. The monitoring and self-recovery of the virtual machine's running status is achieved by deploying a monitoring process and a monitoring platform. The monitoring platform is deployed independently of the virtual machine, while the monitoring process is deployed within the virtual machine but does not require modification of the programs running in the virtual machine, ensuring that the original business is not affected. This solves the technical problem in related technologies where virtual machines are prone to memory overflow, which leads to the inability to handle normal business.
[0024] This disclosure not only detects and alerts virtual machines with high memory usage, but also automatically restores them, effectively shortening the time from detecting virtual machine anomalies to restoring the virtual machine and improving the availability of virtual machines. Attached Figure Description
[0025] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0026] Figure 1 This is a flowchart of an optional virtual machine status monitoring method according to an embodiment of the present invention;
[0027] Figure 2 This is a deployment module diagram of an optional monitoring platform and virtual machine according to an embodiment of the present invention;
[0028] Figure 3 This is a flowchart of an optional monitoring process according to an embodiment of the present invention;
[0029] Figure 4 This is a flowchart of an optional monitoring platform according to an embodiment of the present invention;
[0030] Figure 5 This is a schematic diagram of an optional virtual machine status monitoring device according to an embodiment of the present invention;
[0031] Figure 6 This is a hardware structure block diagram of an electronic device (or mobile device) for a virtual machine status monitoring method according to an embodiment of the present invention. Detailed Implementation
[0032] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0033] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0034] To facilitate understanding of the present invention by those skilled in the art, some terms or nouns involved in the various embodiments of the present invention are explained below:
[0035] VM, or Virtual Machine, refers to a complete computer system simulated by software, which has full hardware system functions and runs in a completely isolated environment. It uses part of the hard disk and memory capacity of the physical machine as the hard disk and memory capacity of the virtual machine. It has its own independent CMOS, hard disk and operating system. It can be operated like a physical machine. All the work that can be done in a physical computer can be done in a virtual machine.
[0036] OOM, Out Of Memory, refers to a memory overflow that occurs when an application system has unrecoverable memory or uses too much memory, ultimately causing the program to require more memory than the maximum available memory. In this case, the program cannot run, and the system will prompt a memory overflow warning, automatically close the software, restart the computer, or release some memory to allow the software to run normally.
[0037] It should be noted that the virtual machine status monitoring method and apparatus in this disclosure can be used in the field of financial technology technology to monitor the running status of virtual machines, and can also be used in any field other than financial technology technology to monitor the running status of virtual machines. This disclosure does not limit the application field of the virtual machine status monitoring method and apparatus.
[0038] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, monitoring data, etc.) disclosed herein are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of such data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding access points are provided for users to choose to authorize or refuse. For example, this system has interfaces with relevant users or organizations. Before obtaining relevant information, a request to obtain the information must be sent to the aforementioned user or organization through the interface, and the relevant information will be obtained only after receiving consent from the aforementioned user or organization.
[0039] The following embodiments of the present invention can be applied to various systems / applications / devices that monitor the running status of virtual machines, improving the availability of virtual machines, increasing the coverage of the monitoring and recovery system, and ensuring that the original services of the virtual machines are not affected. Simultaneously, the present invention employs a memory monitoring process pre-deployed within the internal space of the corresponding virtual machine to detect the memory usage and total number of threads of each virtual machine, determine the memory status of the virtual machine, and send a virtual machine restart request to a monitoring platform independently deployed on each virtual machine and interfaced with the memory monitoring process when a memory overflow anomaly occurs.
[0040] The present invention will now be described in detail with reference to various embodiments.
[0041] Example 1
[0042] According to an embodiment of the present invention, an embodiment of a virtual machine status monitoring method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0043] Figure 1 This is a flowchart of an optional virtual machine status monitoring method according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:
[0044] Step S101: Use a memory monitoring process to detect the memory usage and total number of threads of the virtual machine. The memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine.
[0045] Step S102: The memory monitoring process determines the memory status of the virtual machine based on memory usage and total number of threads.
[0046] Step S103: When the memory status of the virtual machine indicates a memory overflow exception, a virtual machine restart request is sent to the monitoring platform by the memory monitoring process. The monitoring platform is deployed independently of each virtual machine and connects to N memory monitoring processes, where N is an integer greater than or equal to 1.
[0047] Through the above steps, a memory monitoring process pre-deployed in the internal space of the corresponding virtual machine can be used to detect the memory usage and total number of threads of the virtual machine. Based on the memory usage and total number of threads, the memory status of the virtual machine can be determined. If the memory status of the virtual machine indicates a memory overflow anomaly, the memory monitoring process sends a virtual machine restart request to a monitoring platform that is deployed independently of each virtual machine and interfaces with N memory monitoring processes, where N is an integer greater than or equal to 1.
[0048] In this embodiment of the invention, the monitoring process monitors the memory usage of the virtual machine and issues alarms and performs self-recovery, shortening the time for manual monitoring and recovery, and improving the availability of the virtual machine. The monitoring process can also perform parallel detection of the number of threads, monitor memory overflow caused by thread exhaustion, and increase the coverage of the monitoring and recovery system. By deploying the monitoring process and the monitoring platform, the running status of the virtual machine is monitored and self-recovered. The monitoring platform is deployed independently of the virtual machine, and the monitoring process is deployed inside the virtual machine but does not require modification of the programs running in the virtual machine, ensuring that the original business is not affected. This solves the technical problem in related technologies where virtual machines are prone to memory overflow, resulting in the inability to handle normal business.
[0049] The embodiments of the present invention will now be described in detail with reference to the steps described above.
[0050] Step S101: Use a memory monitoring process to detect the memory usage and total number of threads of the virtual machine. The memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine.
[0051] Optionally, step S101 includes: using a memory monitoring process to count the memory usage rate at a predetermined interval (e.g., setting the predetermined interval to 1 minute); using the memory monitoring process to detect each application process currently in running state at a predetermined interval to obtain the total number of threads.
[0052] It should be noted that the memory monitoring process may also detect the following:
[0053] 1. Check the historical error log to see if there are any other anomalies or errors that might have caused the memory overflow;
[0054] 2. Check for memory leaks. If resources remain in a referenced state for a long time without being released, they will consume more and more memory as the runtime increases, eventually leading to memory overflow.
[0055] 3. Detect whether there are infinite loops or malicious code in the program code. Infinite loops and malicious code will cause a memory leak every time they are executed, eventually leading to memory overflow.
[0056] 4. Check if the task queue is correct. If any project tasks are added to the wrong queue, misuse of the thread pool will also lead to memory overflow.
[0057] Step S102: The memory monitoring process determines the memory status of the virtual machine based on memory usage and total number of threads.
[0058] Optionally, step S102 includes: using a memory monitoring process to compare the memory usage rate with a preset usage rate threshold to obtain a memory usage comparison result; if the memory usage comparison result indicates that the memory usage rate is greater than the preset usage rate threshold, incrementing the exception counter by a first specified value; using a memory monitoring process to compare the total number of threads with a preset total number threshold to obtain a thread comparison result; if the thread comparison result indicates that the total number of threads is greater than the preset total number threshold, incrementing the exception counter by a second specified value; if the accumulated value of the exception counter is greater than a preset exception threshold, setting the virtual machine's memory state to memory overflow exception; if the accumulated value of the exception counter is less than or equal to the preset exception threshold, setting the virtual machine's memory state to normal memory.
[0059] For example, if both the first and second specified values are set to 1, the accumulated value of the exception counter is the number of memory exceptions in the virtual machine. If the preset exception threshold is set to 3, then when the number of memory exceptions in the virtual machine exceeds 3, it is determined that the virtual machine has a memory overflow exception.
[0060] It should be noted that the memory usage threshold and the total number of threads threshold are safe values that allow the virtual machine to maintain normal operation without memory leaks, and can be preset by users or developers according to actual needs.
[0061] It should be noted that when the virtual machine's memory status indicates that the memory is normal, the value of the exception counter remains unchanged. The memory monitoring process waits for a predetermined time (for example, the predetermined time is set to 1 minute) to count the memory usage and the total number of threads at the current moment, and repeats the above-mentioned exception counter counting process.
[0062] Step S103: When the memory status of the virtual machine indicates a memory overflow exception, a virtual machine restart request is sent to the monitoring platform by the memory monitoring process. The monitoring platform is deployed independently of each virtual machine and connects to N memory monitoring processes, where N is an integer greater than or equal to 1.
[0063] Optionally, in step S103, after the memory monitoring process sends a virtual machine restart request to the monitoring platform, the method further includes: clearing the count value of the exception counter to zero.
[0064] Optionally, step S103 further includes: responding to the virtual machine restart request and restarting the virtual machine corresponding to the memory monitoring process through the monitoring platform.
[0065] It should be noted that after the monitoring platform receives the virtual machine restart request sent by the monitoring process, the monitoring platform controls the monitoring process to restart the virtual machine it is running on.
[0066] In this embodiment of the invention, the monitoring platform can control the monitoring process to restart the virtual machine it resides in when it receives a restart request initiated by the monitoring process, or it can periodically initiate connectivity detection requests to the interface of the monitoring process and determine whether the monitoring process is running normally based on the test results returned by the interface.
[0067] Optionally, the virtual machine status monitoring method further includes: sending test commands to the memory monitoring process in each virtual machine using a monitoring platform, wherein the test commands are used to verify whether the memory monitoring process is working properly; when the monitoring platform receives a test failure response or no test response from the memory monitoring process, incrementing the virtual machine counter corresponding to the memory monitoring process by a third specified value; when the monitoring platform receives a test success response from the memory monitoring process, resetting the count value of the virtual machine counter corresponding to the memory monitoring process to zero.
[0068] Optionally, after incrementing the virtual machine counter corresponding to the memory monitoring process by a third specified value, the method further includes: if the accumulated value of any virtual machine counter exceeds a preset counting threshold, sending a restart command to the target virtual machine corresponding to the virtual machine counter through the monitoring platform.
[0069] It should be noted that the first specified value, the second specified value, and the third specified value mentioned above can be accumulated on the same counter and compared with the preset counting threshold.
[0070] In this embodiment of the invention, the memory usage of the virtual machine is detected by deploying a memory monitoring process. Compared with the method of code detection, this avoids changing the original program code in the virtual machine, and the monitoring process does not affect the operation of the original program code, thus ensuring that the original business is not affected.
[0071] Meanwhile, the memory monitoring process can automatically issue an alert and request to restart the virtual machine after detecting memory anomalies, which shortens the time for manual monitoring and recovery. After a quick restart, the virtual machine can be put into use quickly, improving the availability of the virtual machine.
[0072] In this embodiment of the invention, by deploying a memory monitoring process, the number of threads running in the virtual machine can be detected in parallel, and the memory overflow caused by the exhaustion of the number of threads can be monitored, thereby increasing the coverage of the monitoring and recovery system.
[0073] The following describes in detail another optional implementation method.
[0074] Figure 2 This is a deployment module diagram of an optional monitoring platform and virtual machine according to an embodiment of the present invention, such as... Figure 2 As shown,
[0075] The monitoring process is deployed inside the virtual machine and is responsible for periodically monitoring the virtual machine's memory usage and current thread count. When an anomaly is detected, it requests the monitoring platform to restart the virtual machine. The virtual machine also contains programs that need to be run.
[0076] The monitoring platform is deployed independently of the virtual machines, located outside the virtual machines, and interfaces with the monitoring process. One monitoring platform can interface with multiple virtual machines, or they can be connected one-to-one. The monitoring platform is responsible for periodically requesting the monitoring process's interface test to check if it is normal, and controlling the monitoring process to restart the virtual machine when the interface test result returns an exception or when it receives a restart request from the monitoring process.
[0077] The monitoring process and the workflow of the monitoring platform are explained below.
[0078] Figure 3 This is a flowchart of an optional monitoring process according to an embodiment of the present invention, such as... Figure 3 As shown, the specific workflow includes:
[0079] 1. Set the monitoring process interval to 1 minute.
[0080] 2. The monitoring process initiates a check on the virtual machine every minute at preset time intervals to obtain memory usage and total number of threads (corresponding to...). Figure 3 (Detecting the number of threads in the virtual machine).
[0081] 3. The monitoring process compares the obtained memory usage rate and total number of threads with preset thresholds. Each time the threshold is exceeded, the counter is incremented by 1. If neither the memory usage rate nor the total number of threads exceeds the threshold, the counter is reset. After the counter is cleared to zero, the monitoring process waits for 1 minute before initiating the detection again.
[0082] 4. Set the counting threshold to 3.
[0083] 5. If the counter count does not exceed the preset threshold, the monitoring process will wait for 1 minute and then initiate the detection again. When the counter count exceeds the preset threshold, the monitoring process will send a request to the monitoring platform to restart the virtual machine. After the request is sent, the counter will be cleared to zero.
[0084] The monitoring process monitors the virtual machine's memory usage and total number of threads according to the above procedure, and requests the monitoring platform to restart the virtual machine when an anomaly is detected.
[0085] Figure 4 This is a flowchart of an optional monitoring platform according to an embodiment of the present invention, such as... Figure 4 As shown, the specific workflow includes:
[0086] 1. Set the monitoring platform's time interval to 1 minute.
[0087] 2. The monitoring platform sends a test request to the monitoring process of each virtual machine every minute at a preset time interval (to test the monitoring process of all registered virtual machines) to verify whether the monitoring process is operating normally.
[0088] 3. Wait for the monitoring process to return the test results. If the monitoring process returns the test request normally, reset the counter of the virtual machine and clear the counter of the corresponding virtual machine to zero. The monitoring platform will wait for 1 minute and then initiate the test request again.
[0089] 4. If a test request from a monitoring process in a virtual machine fails or does not respond, the counter of the corresponding virtual machine is incremented by 1.
[0090] 5. Set the counting threshold to 3.
[0091] 6. If the counter value does not exceed the counting threshold, the monitoring platform will wait for 1 minute and then initiate the test request again.
[0092] 7. If the counter value of a virtual machine exceeds the counting threshold, the monitoring platform will restart the virtual machine to restore it. After restarting, the counter of the virtual machine will be reset to zero.
[0093] 8. When the monitoring platform receives a restart request from a certain monitoring process, the monitoring platform restarts the virtual machine where the monitoring process is located, and after restarting, resets the counter to zero.
[0094] The monitoring platform periodically checks whether the monitoring process is normal according to the above process. If the monitoring process is abnormal, the virtual machine will be restarted to restore it, or the virtual machine will be restarted to restore it after the monitoring platform receives a restart request initiated by the monitoring process.
[0095] Through the above implementation methods, virtual machines with high memory usage can be detected, alerted, and self-recovered, significantly reducing the time from manual anomaly detection to recovery, and improving recovery efficiency and virtual machine availability. Simultaneously, this invention can also monitor memory overflow caused by thread exhaustion in virtual machines, increasing the coverage of the monitoring and recovery system.
[0096] The monitoring system in this embodiment of the invention consists of a monitoring platform outside the virtual machine and a monitoring process deployed inside the virtual machine. The monitoring process does not interfere with the original program execution in the virtual machine, and the monitoring platform's control over the monitoring process does not change the program's content. The operation of the entire monitoring system does not affect the original program's execution in any way.
[0097] The following is a detailed description with reference to another embodiment.
[0098] Example 2
[0099] The virtual machine status monitoring device provided in this embodiment includes multiple implementation units, each of which corresponds to a specific implementation step in Embodiment 1 above.
[0100] Figure 5 This is a schematic diagram of an optional virtual machine status monitoring device according to an embodiment of the present invention, such as... Figure 5 As shown, the status monitoring device may include: a detection unit 50, a determination unit 51, and a transmission unit 52, wherein...
[0101] The detection unit 50 is used to detect the memory usage and total number of threads of the virtual machine using a memory monitoring process, wherein the memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine.
[0102] The determination unit 51 is used to determine the memory status of the virtual machine based on the memory usage rate and the total number of threads by using the memory monitoring process.
[0103] Sending unit 52 is used to send a virtual machine restart request to the monitoring platform through the memory monitoring process when the memory status indication of the virtual machine shows a memory overflow exception. The monitoring platform is deployed independently of each virtual machine and connects to N memory monitoring processes, where N is an integer greater than or equal to 1.
[0104] The aforementioned status monitoring device can detect the memory usage and total number of threads of the virtual machine through the detection unit 50 using a memory monitoring process pre-deployed in the internal space of the corresponding virtual machine. The determination unit 51 determines the memory status of the virtual machine based on the memory usage and total number of threads. When the memory status of the virtual machine indicates a memory overflow abnormality, the sending unit 52 uses the memory monitoring process to send a virtual machine restart request to a monitoring platform that is deployed independently of each virtual machine and interfaces with N memory monitoring processes, where N is an integer greater than or equal to 1.
[0105] In this embodiment of the invention, the monitoring process monitors the memory usage of the virtual machine and performs alarms and self-recovery, shortening the time for manual monitoring and recovery, and improving the availability of the virtual machine. The monitoring process can also perform parallel detection of the number of threads, monitor memory overflow caused by thread exhaustion, and increase the coverage of the monitoring and recovery system. By deploying the monitoring process and the monitoring platform, the running status of the virtual machine is monitored and self-recovered. The monitoring platform is deployed independently of the virtual machine, and the monitoring process is deployed inside the virtual machine but does not require modification of the running programs in the virtual machine, ensuring that the original business is not affected. This solves the technical problem in related technologies that virtual machines are prone to memory overflow, resulting in the inability to handle normal business.
[0106] Optionally, the detection unit includes: a statistics module, used to use the memory monitoring process to count the memory usage rate at a predetermined interval (e.g., the predetermined interval is set to 1 minute) at a time; and a detection module, used to use the memory monitoring process to detect each application process that is currently running at a predetermined interval, and obtain the total number of threads.
[0107] It should be noted that the memory monitoring process may also detect the following:
[0108] 1. Check the historical error log to see if there are any other anomalies or errors that might have caused the memory overflow;
[0109] 2. Check for memory leaks. If resources remain in a referenced state for a long time without being released, they will consume more and more memory as the runtime increases, eventually leading to memory overflow.
[0110] 3. Detect whether there are infinite loops or malicious code in the program code. Infinite loops and malicious code will cause a memory leak every time they are executed, eventually leading to memory overflow.
[0111] 4. Check if the task queue is correct. If any project tasks are added to the wrong queue, misuse of the thread pool will also lead to memory overflow.
[0112] Optionally, the determining unit includes: a first comparison module, used to compare the memory usage rate with a preset usage rate threshold using a memory monitoring process to obtain a memory usage comparison result; a first increment module, used to increment the exception counter by a first specified value when the memory usage comparison result indicates that the memory usage rate is greater than the preset usage rate threshold; a second comparison module, used to compare the total number of threads with a preset total number threshold using a memory monitoring process to obtain a thread comparison result; a second increment module, used to increment the exception counter by a second specified value when the thread comparison result indicates that the total number of threads is greater than the preset total number threshold; a first state setting module, used to set the virtual machine's memory state to memory overflow exception when the accumulated value of the exception counter is greater than a preset exception threshold; and a second state setting module, used to set the virtual machine's memory state to memory normal when the accumulated value of the exception counter is less than or equal to the preset exception threshold.
[0113] For example, if both the first and second specified values are set to 1, the accumulated value of the exception counter is the number of memory exceptions in the virtual machine. If the preset exception threshold is set to 3, then when the number of memory exceptions in the virtual machine exceeds 3, it is determined that the virtual machine has a memory overflow exception.
[0114] It should be noted that the memory usage threshold and the total number of threads threshold are safe values that allow the virtual machine to maintain normal operation without memory leaks, and can be preset by users or developers according to actual needs.
[0115] It should be noted that when the virtual machine's memory status indicates that the memory is normal, the value of the exception counter remains unchanged. The memory monitoring process waits for a predetermined time (for example, the predetermined time is set to 1 minute) to count the memory usage and the total number of threads at the current moment, and repeats the above-mentioned exception counter counting process.
[0116] Optionally, the virtual machine status monitoring device further includes: a first clearing module, used to clear the count value of the exception counter to zero after the sending unit sends a virtual machine restart request to the monitoring platform using the memory monitoring process.
[0117] In this embodiment of the invention, the monitoring platform can control the monitoring process to restart the virtual machine it resides in when it receives a restart request initiated by the monitoring process, or it can periodically initiate connectivity detection requests to the interface of the monitoring process and determine whether the monitoring process is running normally based on the test results returned by the interface.
[0118] Optionally, the virtual machine status monitoring device further includes: a first sending module, used to send test commands to the memory monitoring process in each virtual machine using the monitoring platform, wherein the test commands are used to verify whether the memory monitoring process is working normally; a third incrementing module, used to increment the virtual machine counter corresponding to the memory monitoring process by a third specified value when the monitoring platform receives a test failure response or no test response from the memory monitoring process; and a second clearing module, used to clear the count value of the virtual machine counter corresponding to the memory monitoring process to zero when the monitoring platform receives a test normal response from the memory monitoring process.
[0119] Optionally, the virtual machine status monitoring device further includes: a second sending module, used to send a restart command to the target virtual machine corresponding to the virtual machine counter after the third sending module increments the virtual machine counter corresponding to the memory monitoring process by a third specified value, and if the accumulated value of any virtual machine counter is greater than a preset counting threshold, using the monitoring platform.
[0120] It should be noted that the first specified value, the second specified value, and the third specified value mentioned above can be accumulated on the same counter and compared with the preset counting threshold.
[0121] Optionally, the virtual machine status monitoring device further includes a response module, which is used to respond to the virtual machine restart request after the sending unit sends a virtual machine restart request to the monitoring platform using the memory monitoring process, and restart the virtual machine corresponding to the memory monitoring process through the monitoring platform.
[0122] It should be noted that after the monitoring platform receives the virtual machine restart request sent by the monitoring process, the monitoring platform controls the monitoring process to restart the virtual machine it is running on.
[0123] The aforementioned status monitoring device may also include a processor and a memory. The aforementioned detection unit 50, determination unit 51, and sending unit 52 are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.
[0124] The aforementioned processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and by adjusting kernel parameters, virtual machine restart requests can be sent to a monitoring platform deployed independently of each virtual machine.
[0125] The aforementioned memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0126] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: using a memory monitoring process to detect the memory usage and total number of threads of a virtual machine, wherein the memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine; using the memory monitoring process to determine the memory status of the virtual machine based on the memory usage and total number of threads; and using the memory monitoring process to send a virtual machine restart request to a monitoring platform when the memory status of the virtual machine indicates a memory overflow exception, wherein the monitoring platform is deployed independently of each virtual machine, and the monitoring platform interfaces with N memory monitoring processes, where N is an integer greater than or equal to 1.
[0127] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein, when the computer program is running, a virtual machine state monitoring method for controlling the device where the computer-readable storage medium is located to execute any of the above-mentioned methods is provided.
[0128] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the virtual machine state monitoring method of any of the above.
[0129] Figure 6 This is a hardware structure block diagram of an electronic device (or mobile device) for a virtual machine state monitoring method according to an embodiment of the present invention. Figure 6 As shown, an electronic device may include one or more ( Figure 6 The processor 602 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 604 for storing data may also be included. In addition, it may include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 6 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, the electronic device may also include components that are more... Figure 6 The more or fewer components shown, or having the same Figure 6 The different configurations shown.
[0130] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0131] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0132] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0133] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0134] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0135] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0136] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for monitoring the status of a virtual machine, characterized in that, include: A memory monitoring process is used to detect the memory usage and total number of threads of the virtual machine, wherein the memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine; The memory monitoring process determines the memory status of the virtual machine based on the memory usage rate and the total number of threads, including: comparing the memory usage rate with a preset usage rate threshold to obtain a memory usage comparison result; incrementing an exception counter by a first specified value when the memory usage comparison result indicates that the memory usage rate is greater than the preset usage rate threshold; comparing the total number of threads with a preset total number threshold to obtain a thread comparison result; incrementing an exception counter by a second specified value when the thread comparison result indicates that the total number of threads is greater than the preset total number threshold; setting the memory status of the virtual machine to memory overflow exception when the accumulated value of the exception counter is greater than a preset exception threshold; and setting the memory status of the virtual machine to normal memory when the accumulated value of the exception counter is less than or equal to the preset exception threshold. When the memory status indicator of the virtual machine shows a memory overflow exception, the memory monitoring process sends a virtual machine restart request to the monitoring platform. The monitoring platform is deployed independently of each virtual machine and connects to N memory monitoring processes, where N is an integer greater than or equal to 1. The method further includes: sending a test command to the memory monitoring process in each virtual machine using the monitoring platform, wherein the test command is used to verify whether the memory monitoring process is working normally; when the monitoring platform receives a test failure response or no test response from the memory monitoring process, incrementing the virtual machine counter corresponding to the memory monitoring process by a third specified value; when the monitoring platform receives a test success response from the memory monitoring process, resetting the count value of the virtual machine counter corresponding to the memory monitoring process to zero.
2. The status monitoring method according to claim 1, characterized in that, The steps for using a memory monitoring process to detect the virtual machine's memory usage and total number of threads include: The memory monitoring process calculates the memory usage rate at predetermined intervals. The memory monitoring process detects each application process currently in operation at predetermined intervals to obtain the total number of threads.
3. The status monitoring method according to claim 1, characterized in that, After sending a virtual machine restart request to the monitoring platform using the memory monitoring process, the process also includes: Clear the count value of the exception counter to zero.
4. The status monitoring method according to claim 1, characterized in that, After incrementing the virtual machine counter corresponding to the memory monitoring process by a third specified value, the process also includes: If the accumulated value of any of the virtual machine counters exceeds a preset counting threshold, the monitoring platform sends a restart command to the target virtual machine corresponding to the virtual machine counter.
5. The status monitoring method according to claim 1, characterized in that, After sending a virtual machine restart request to the monitoring platform using the memory monitoring process, the process also includes: In response to the virtual machine restart request, the virtual machine corresponding to the memory monitoring process is restarted through the monitoring platform.
6. A virtual machine status monitoring device, characterized in that, include: The detection unit is used to detect the memory usage and total number of threads of the virtual machine using a memory monitoring process, wherein the memory monitoring process is pre-deployed in the internal space of the corresponding virtual machine; The determining unit is used to determine the memory status of the virtual machine based on the memory occupancy rate and the total number of threads using the memory monitoring process; The determining unit includes: a first comparison module, used to compare the memory usage rate with a preset usage rate threshold using the memory monitoring process to obtain a memory usage comparison result; a first increment module, used to increment an exception counter by a first specified value when the memory usage comparison result indicates that the memory usage rate is greater than the preset usage rate threshold; a second comparison module, used to compare the total number of threads with a preset total number threshold using the memory monitoring process to obtain a thread comparison result; a second increment module, used to increment an exception counter by a second specified value when the thread comparison result indicates that the total number of threads is greater than the preset total number threshold; a first state setting module, used to set the memory state of the virtual machine to memory overflow exception when the accumulated value of the exception counter is greater than a preset exception threshold; and a second state setting module, used to set the memory state of the virtual machine to memory normal when the accumulated value of the exception counter is less than or equal to a preset exception threshold. The sending unit is used to send a virtual machine restart request to the monitoring platform using the memory monitoring process when the memory status indication of the virtual machine shows a memory overflow exception. The monitoring platform is deployed independently of each of the virtual machines and the monitoring platform interfaces with N memory monitoring processes, where N is an integer greater than or equal to 1. The device further includes: a first sending module, used to send a test command to the memory monitoring process in each of the virtual machines using the monitoring platform, wherein the test command is used to verify whether the memory monitoring process is working normally; a third incrementing module, used to increment the virtual machine counter corresponding to the memory monitoring process by a third specified value when the monitoring platform receives a test failure response or no test response from the memory monitoring process; and a second clearing module, used to clear the count value of the virtual machine counter corresponding to the memory monitoring process to zero when the monitoring platform receives a test normal response from the memory monitoring process.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the virtual machine status monitoring method according to any one of claims 1 to 5.
8. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the virtual machine state monitoring method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Thread flow control method and thread flow control device
CN104572277A
Virtual machine process monitoring method, device and system
CN105590054A
