Terminal network abnormity diagnosis and troubleshooting method and readable storage medium
By employing hierarchical network diagnostics and indexing technology, the problem of misaligned and lost log records when the terminal network is abnormal has been solved, ensuring that critical information is uploaded to the cloud and enabling accurate fault location and efficient troubleshooting.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CONTEMPORARY NEBULA TECH ENERGY CO LTD
- Filing Date
- 2025-12-15
- Publication Date
- 2026-05-01
AI Technical Summary
In existing technologies, log records are prone to misalignment or loss when the terminal network is abnormal, making troubleshooting difficult. Furthermore, abnormal information is not uploaded to the cloud in a timely manner, making it difficult to reconstruct the fault occurrence process.
A hierarchical network diagnostic method is used to generate diagnostic logs, and the logs are associated with the diagnostic logs through the first index record and the second index record. Fault window logs are marked to ensure that they are uploaded to the cloud when the network is restored.
It enables efficient log retention and diagnosis in the event of network anomalies, allowing the cloud to accurately locate fault paths and improve terminal maintainability and fault handling efficiency.
Smart Images

Figure CN121967184A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of log management technology, and in particular to a method for diagnosing and troubleshooting terminal network anomalies and a readable storage medium. Background Technology
[0002] With the large-scale deployment of IoT devices, edge computing terminals, and smart monitoring devices, the reliance of terminals on network connectivity stability during long-term operation has significantly increased. Terminals typically report data, perform remote control, and synchronize status through cloud platforms. When network anomalies occur, terminals not only fail to communicate normally but may also face difficulties in troubleshooting due to incomplete log records or lost abnormal information. In existing technologies, terminals often use a single log file or linear storage to record operational information. However, such methods are prone to problems such as record misalignment, log loss, or chaotic log overwriting in cases of power failure, restart, storage corruption, or log space exhaustion, failing to guarantee long-term, continuous, and reliable preservation of critical operational trajectories.
[0003] Meanwhile, if the terminal is unable to report logs during network anomalies, and key operational information before and after the anomaly is not effectively retained, the cloud will be unable to reconstruct the fault process after the network is restored, making it difficult to accurately analyze the cause of the anomaly. Some technologies attempt to alleviate this problem by periodically recording logs locally, but there is a lack of correlation between logs and anomaly events, and existing storage structures also struggle to prioritize the protection and rapid retrieval of important diagnostic information. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a method for diagnosing and troubleshooting terminal network anomalies and a readable storage medium that can completely retain the fault path and diagnostic basis when a network anomaly occurs.
[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: A method for diagnosing and troubleshooting terminal network anomalies, characterized by comprising the following steps: S1. Obtain running information and generate corresponding running logs, and generate a first index record based on the running logs; S2. Based on the triggering of the terminal network anomaly, perform hierarchical network diagnosis on the terminal and locate the level of the network anomaly, and generate a corresponding diagnostic log and a second index record corresponding to the diagnostic log; S3. Record the trigger time of the hierarchical network diagnosis, and add an association identifier to the operation log within a preset time range before and after the trigger time, and mark it as a fault window log; the association identifier is used to associate the operation log and the diagnosis log; S4. When network recovery is detected, the diagnostic log and the fault window log are uploaded to the cloud based on the first index record and the second index record.
[0006] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows: A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program, which, when executed by a processor, performs the following steps: S1. Obtain running information and generate corresponding running logs, and generate a first index record based on the running logs; S2. Based on the triggering of the terminal network anomaly, perform hierarchical network diagnosis on the terminal and locate the level of the network anomaly, and generate a corresponding diagnostic log and a second index record corresponding to the diagnostic log; S3. Record the trigger time of the hierarchical network diagnosis, and add an association identifier to the operation log within a preset time range before and after the trigger time, and mark it as a fault window log; the association identifier is used to associate the operation log and the diagnosis log; S4. When network recovery is detected, the diagnostic log and the fault window log are uploaded to the cloud based on the first index record and the second index record.
[0007] The beneficial effects of this invention are as follows: It provides a method for diagnosing and troubleshooting terminal network anomalies and a readable storage medium. By generating a first index record and a second index record for the operation log and diagnostic log respectively, a structured correspondence is maintained between the log text and the index information. This structured principle ensures that the terminal can quickly locate the target content in massive logs through the index, without needing to sequentially scan the log text, thereby significantly improving query efficiency. When a network anomaly is triggered, a separate diagnostic log is generated by performing hierarchical network diagnosis, and the operation logs before and after the trigger time are marked as fault window logs, establishing a time-linked association between the operation logs and the diagnostic logs. Uploading these logs based on the first and second index records ensures that the cloud can obtain the complete fault path and diagnostic basis, thereby achieving accurate location and efficient troubleshooting of network anomalies and improving the maintainability of the terminal. Attached Figure Description
[0008] Figure 1 This is a flowchart illustrating a method for diagnosing and troubleshooting terminal network anomalies according to an embodiment of the present invention. Figure 2 This is a schematic diagram of a terminal network anomaly diagnosis and troubleshooting method according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the collaborative workflow in a terminal network anomaly diagnosis and troubleshooting method according to an embodiment of the present invention. Detailed Implementation
[0009] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.
[0010] Definitions: Layered network diagnostics: Based on the layered structure of network protocols, this approach analyzes and troubleshoots each layer of the network system, such as the physical layer, data link layer, network layer, transport layer, and application layer. Layered diagnostics allows for accurate location of the specific layer at which a network fault occurs, improving the efficiency of fault detection.
[0011] In existing technologies, in scenarios where IoT terminals, smart monitoring devices, and various embedded devices are widely used, terminals typically need to report data and perform remote management with the cloud via cellular networks or local area networks. To ensure the maintainability of devices during long-term operation, terminals generally have local logging capabilities to save operational status, network communication processes, and abnormal event information. However, existing log recording generally uses continuous writing or single-file storage methods. Due to limitations such as frequent power outages and restarts of terminals and limited storage space, logs are prone to overwriting, writing interruptions, or missing records, making it difficult to guarantee the integrity of critical operational trajectories. Furthermore, when the network is interrupted, the terminal cannot upload abnormal information to the cloud in a timely manner. Operational logs before and after the anomaly are often crucial for fault location, but existing mechanisms struggle to correlate these logs with abnormal events. This makes it difficult for the cloud to reconstruct the anomaly process after network recovery, impacting fault location efficiency.
[0012] To at least solve the above problems, please refer to Figure 1 This invention provides a method for diagnosing and troubleshooting terminal network anomalies, including the following steps: S1. Obtain running information and generate corresponding running logs, and generate a first index record based on the running logs; S2. Based on the triggering of the terminal network anomaly, perform hierarchical network diagnosis on the terminal and locate the level of the network anomaly, and generate a corresponding diagnostic log and a second index record corresponding to the diagnostic log; the association identifier is used to associate the operation log and the diagnostic log. S3. Record the trigger time of the hierarchical network diagnosis, add an association identifier to the operation log within a preset time range before and after the trigger time, and mark it as a fault window log; S4. When network recovery is detected, the diagnostic log and the fault window log are uploaded to the cloud based on the first index record and the second index record.
[0013] As described above, the beneficial effects of this invention are as follows: By generating a first index record and a second index record for the operation log and diagnostic log respectively, a structured correspondence is maintained between the log text and the index information. This structured principle ensures that the terminal can quickly locate the target content in massive logs through the index, without having to sequentially scan the log text, thereby significantly improving query efficiency. When a network anomaly is triggered, a separate diagnostic log is generated by performing hierarchical network diagnosis, and the operation logs before and after the trigger time are marked as fault window logs, establishing a time-linked association between the operation logs and the diagnostic logs. Uploading these logs based on the first and second index records ensures that the cloud can obtain a complete fault path and diagnostic basis, thereby achieving accurate location and efficient troubleshooting of network anomalies and improving the maintainability of the terminal.
[0014] In some implementations, step S0 is included before step S1: A log management information area, an index record area, and a log text area are generated in the terminal's memory, and the write positions for the index record area and the log text area are generated in the log management information area. Step S1 specifically includes: Obtain runtime information and generate corresponding runtime logs, generate a first index record based on the runtime logs; generate a write position based on the log management information area, write the runtime logs into the log body area, and generate a first index record in the index record area; Step S2 specifically includes: Based on the triggering of the terminal network anomaly, a hierarchical network diagnosis is performed on the terminal to locate the level of the network anomaly, and a corresponding diagnostic log and a second index record corresponding to the diagnostic log are generated; the second index record is written to a preset priority position in the index record area with high priority.
[0015] As described above, by dividing the terminal storage into a log management information area, an index record area, and a log text area, log data is managed in a partitioned manner, resulting in a clear structure and explicit access. The log management information records key fields such as write position, guiding runtime and diagnostic logs to be accurately written to designated areas, avoiding overwriting errors or misplaced writes. Simultaneously, the second index record of the diagnostic log is written to a preset priority position in the index record area, giving critical diagnostic data higher retrieval and transmission priority. This mechanism ensures that diagnostic logs are not overwritten by ordinary logs even when logs are frequently written or storage space is nearing its limit, enabling immediate transmission to the cloud after network recovery, thereby improving fault handling efficiency.
[0016] In some embodiments, step S0 further includes: In the memory, the log management information area is stored using at least two redundant copies; The integrity of the redundant copies is verified and the redundant copies that pass the verification are marked as valid copies. The write positions of the index record area and the log text area are generated based on the valid copies.
[0017] As described above, by providing at least two redundant copies of the log management information area and selecting the valid copy for recovery based on integrity checks, the principle behind this multi-copy mechanism is that it can prevent the log system from failing due to power outages, write interruptions, or storage corruption of single metadata. When a piece of management information is corrupted, the system can automatically recover to another valid copy, thus ensuring that key metadata such as log write position, cycle state, and offset remain correct. Therefore, it can be inferred that this scheme significantly enhances the fault tolerance and recoverability of the log system, ensuring the continuity and reliability of the log structure during long-term system operation.
[0018] In some embodiments, step S0 further includes: When the write position of the index record area reaches the end, the write position cycles back to the beginning position of the index record area and overwrites the earliest generated index record.
[0019] As described above, by setting the index record area as a circular structure, the write position automatically cycles back to the beginning position and overwrites the earliest generated index record when it reaches the end of the area. The principle is to treat the index area as a circular buffer, allowing limited storage space to be reused infinitely, avoiding the problem of manual cleanup or interruption of writes after the traditional linear structure is full. This method not only ensures that the terminal continuously generates log indexes during long-term operation but also maintains the orderliness and computability of the index structure, thereby improving the stability and maintainability of the log system.
[0020] In some implementations, step S2, which involves performing layered network diagnostics on the terminal, specifically includes: The system reads whether the link in the terminal's status register is established. If the link in the status register is disconnected, it is determined to be a physical layer fault, and a corresponding diagnostic log is generated. The system counts the packet loss rate and round-trip time of the terminal. If the packet loss rate exceeds a preset threshold or the round-trip time exceeds a preset delay, it is determined to be a network layer fault, and a corresponding diagnostic log is generated. A TCP connection is established with the target server. If the TCP connection is abnormally disconnected or the handshake delay exceeds a preset threshold, it is determined to be a transport layer fault, and a corresponding diagnostic log is generated. The system detects the response status of the application protocol. When the response status is abnormal, it is determined to be an application layer fault, and a corresponding diagnostic log is generated.
[0021] As described above, layered network diagnostics assesss network anomalies based on physical layer link status, network layer packet loss rate and round-trip latency, transport layer TCP connection establishment, and application layer protocol response. For example, link disconnections are typically caused by physical connection problems; increased packet loss rate or latency corresponds to network layer link quality issues; TCP handshake anomalies reflect transport layer problems; and application layer response failures indicate problems with upper-layer service or business links. Through this progressive, layer-by-layer detection, the terminal can accurately categorize network anomalies to specific layers, and the generated diagnostic logs clearly indicate the source of the anomalies. This facilitates rapid fault identification by cloud and operations personnel, significantly improving fault location accuracy and reducing on-site troubleshooting time.
[0022] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of a method for diagnosing and troubleshooting terminal network anomalies.
[0023] Please refer to Figure 1 and Figure 2 The embodiments of the present invention are as follows: This invention provides a method for diagnosing and troubleshooting terminal network anomalies, applicable to terminal devices with external non-volatile memory, such as external FLASH. This embodiment divides the memory into a log management information area, an index record area, and a log text area. The log management information area records the write positions, log sequence numbers, area boundaries, and cyclic overwriting status of the index record area and log text area. The index record area stores the starting address and length of each log text entry. The log text area sequentially stores each running log and diagnostic log. During initialization, the terminal restores the write positions of the index and log text based on the log management information area, ensuring the consistency of the log structure after power outages, restarts, or other events. The log management information area uses two redundant copies for storage. The terminal performs integrity checks on the redundant copies and selects the valid copy to restore the write position. Since the log management information area contains the core pointers and operating status of the log system, damage to it could cause the log system to malfunction. Therefore, the redundant copies and verification mechanism significantly improve the system's recovery capabilities in scenarios involving power outages, write interruptions, or storage corruption, providing higher traceability and stability during long-term terminal operation.
[0024] Specifically, the memory is divided into a log management information area, an index record area, and a log text area, corresponding to the metadata area, index area, and data area, respectively. Its code structure is as follows:
[0025] The main code structure in the memory is as follows: Magic number, used to identify the validity and version of metadata; Version number, identifying the version of the metadata format; Index start address (index_start), indicating the starting position of the index record area; Data start and end addresses (data_start, data_end), defining the scope of the log data storage area; Next index write position (next_index) and next data write address (next_data_addr), the write position of the next log index and data; Total log entries (total_entries), recording the total number of log entries stored in the current log system; Index and data area loop wrap count (index_wrap_count, data_wrap_count), used to track the number of loop writes in the index and data areas, assisting in log wrap management; CRC32 checksum, used to verify the integrity of metadata and prevent data corruption.
[0026] During operation, the terminal continuously acquires operational information and generates corresponding log text. Based on the write position recorded in the log management information area, the log text is written to the log text area, and a corresponding index record is generated in the index record area. The index record is stored with a fixed length, allowing its address to be directly calculated from the area's starting address and a fixed offset, reducing addressing complexity. Simultaneously, when the write position in the index record area reaches the end of the area, the write position wraps back to the area's starting address and overwrites the earliest generated index record. This wraparound mechanism forms a circular index structure, enabling the index area to be continuously and cyclically used within a fixed space, preventing service interruption due to storage space exhaustion, thus meeting the long-term operational needs of the terminal device.
[0027] When a terminal detects a network anomaly, it performs layered network diagnostics sequentially at the physical layer, network layer, transport layer, and application layer. Specifically, it reads the terminal's link state register to determine if a physical link has been established; it assesses network layer quality by analyzing packet loss rate and round-trip latency; it attempts to establish a TCP connection with the target server to determine if the transport layer is functioning correctly; and it judges the status of upper-layer services based on application protocol responses. Since anomalies at different layers exhibit different characteristics—for example, a broken link corresponds to a physical layer fault, packet loss or increased latency corresponds to a network layer quality problem, TCP handshake delays or interruptions correspond to transport layer anomalies, and application layer response anomalies correspond to service link anomalies—the terminal can accurately categorize anomalies to their specific layer. After obtaining the anomaly level, the terminal generates a corresponding structured diagnostic log and writes its corresponding second index record to a preset priority position in the index record area with high priority, giving the diagnostic log higher priority during subsequent retrieval and uploading.
[0028] In the case of a physical layer fault, the diagnostic log includes register values and a fault description, for example: {"timestamp": 1717023000, "layer": "PHY", "error": "Link down", "register": "0x10", "value": "0x0000"} When a network layer failure occurs, its diagnostic log includes recording metrics such as packet loss rate and latency, for example: {"timestamp": 1717023000, "layer": "NET", "error": "Packet loss", "loss_rate": "75%", "avg_delay": "150ms"} When a transport layer failure occurs, its diagnostic log includes records of connection delays and the reasons for the disconnection, for example: {"timestamp": 1717023000, "layer": "TCP", "error": "Connectiontimeout", "target": "cloud.com:1883", "delay": "2000ms"} When an application layer failure occurs, its diagnostic log includes recording protocol error information, such as: {"timestamp": 1717023000, "layer": "APP", "error": "MQTT heartbeatmissing", "broker": "cloud.com:1883", "timeout": "5s"} The terminal records the trigger time of the hierarchical network diagnosis and adds a correlation identifier to the operation logs within a preset time range before and after the trigger time, marking them as fault window logs. The fault window logs correspond to the first index record mentioned above. The operation logs before and after the diagnosis usually contain the preconditions that led to the fault and the changes in the system state after the fault. Correlating them with the diagnosis logs in time can form a complete fault occurrence chain, which helps cloud systems or operation and maintenance personnel to accurately perform time-series review.
[0029] When the terminal detects network recovery, based on the preset priority positions in the index record area (specifically, the first and second index records), it prioritizes uploading diagnostic logs to the cloud and then sequentially reports fault window logs. The cloud server, through collaborative analysis of the diagnostic logs and fault window logs, can quickly identify the cause and scope of the fault, enabling rapid location, automated analysis, and remote troubleshooting of network anomalies. It also generates visual query reports and applies AI for anomaly detection. This embodiment ensures that the most critical diagnostic information is obtained immediately after network recovery, improving operational decision-making efficiency and significantly reducing fault handling time.
[0030] The collaborative workflow is as follows: Mermaid: flowchart TB Start [Device boot] --> Init [Initialize tertiary storage] Init --> NetCheck{Network connectivity?} NetCheck ----> Normal [Normal Mode: Real-time log upload] NetCheck --No-->Diag [Trigger Layered Network Diagnostics] Diag --> Save [Store the diagnostic results in the index header] Save --> Log [Associate log entry tagged "NET_FAULT"] Log --> Recovery {Network restored?} Recovery ----> Upload [Prioritize uploading diagnostic data] Upload --> Normal Preferably, please refer to Figure 3 The collaborative workflow of the above architecture is as follows: This process is used to enable the terminal to perform self-diagnosis, log association storage, and data upload control after network recovery in the event of network anomalies. The specific process includes the following steps.
[0031] First, after the device starts up, the system enters the initialization phase, configuring the preset three-level storage area. The three-level storage area includes at least a metadata area for storing global state and control information, an index area for recording log index relationships, and a data area for storing specific log content. This initialization process ensures that the log system is in a writable and indexable working state.
[0032] After initialization, the system checks the current network connectivity. This check determines whether the terminal has the ability to communicate normally with the external network. When the check indicates that the network is connected, the system enters normal operation mode and uploads the log information generated during operation in real time according to a preset strategy, thereby realizing online transmission and remote monitoring of log data.
[0033] When the detection result indicates that the network is in a disconnected state, the system triggers the network anomaly handling procedure. Specifically, the system performs a hierarchical network diagnostic operation, checking different layers related to network connectivity layer by layer to determine the possible location or cause of the network anomaly. The hierarchical diagnosis can be performed in order from the bottom layer to the top layer to improve the accuracy and traceability of the diagnostic results.
[0034] After completing the hierarchical network diagnostics, the system writes the corresponding diagnostic results to a preset location in the index area, preferably storing them in the header region of the index area so that they can be prioritized for location during subsequent retrieval. Simultaneously, the system associates the diagnostic results with logs from the corresponding time period, marking the relevant logs as network anomaly logs to achieve correlated storage between network faults and operational logs.
[0035] After storing and logging the diagnostic results, the system continuously monitors the network status to determine if the network has recovered. If the network has not yet recovered, the system returns to continue executing the hierarchical network diagnostic process, updating the diagnostic results periodically, thus forming a closed-loop anomaly monitoring and recording process.
[0036] When network recovery is detected, the system exits the exception handling process and prioritizes uploading the log data previously marked as network anomalies. This ensures that critical diagnostic information and related logs generated during the network outage can be promptly synchronized to the remote system after network recovery, thus providing complete data support for subsequent fault analysis and maintenance.
[0037] This invention constructs a log structure system in memory, consisting of a log management information area, an index record area, and a log text area. This allows terminal operation information to be written to disk in an orderly manner according to its write position, and enables rapid location through the index record. The log management information area employs redundant copies and integrity checks, allowing for the recovery of valid copies in the event of power failure, write interruption, or storage damage, ensuring the continuity and recoverability of the log structure. The index record area uses a full-wrap ring structure and stores index records of fixed length, enabling direct location of the index at a fixed offset, achieving constant-time log retrieval, and thus achieving long-term stable log recording within limited storage space.
[0038] In terms of network anomaly handling, this invention performs layered network diagnostics sequentially at the physical, network, transport, and application layers. It utilizes parameters such as link status, packet loss rate, round-trip time, TCP connection establishment, and application response to determine faults layer by layer, achieving accurate identification of the anomaly source and generating structured diagnostic logs. The index records corresponding to the diagnostic logs are written to a priority position in the index record area, ensuring higher access priority during retrieval and data transmission. By recording the diagnostic trigger time and attaching correlation identifiers to the logs before and after the trigger, a fault window log is formed, which can fully reflect the cause and effect of the fault. After network recovery, the terminal prioritizes uploading the diagnostic logs and fault window logs. The cloud performs collaborative analysis based on structured information and timelines, enabling rapid reproduction of the fault process and identification of the root cause.
[0039] Embodiment 2 of the present invention is as follows: A computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in the terminal network anomaly diagnosis and troubleshooting method of Embodiment 1.
[0040] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for diagnosing and troubleshooting terminal network anomalies, characterized in that, Including the following steps: S1. Obtain running information and generate corresponding running logs, and generate a first index record based on the running logs; S2. Based on the triggering of the terminal network anomaly, perform hierarchical network diagnosis on the terminal and locate the level of the network anomaly, and generate a corresponding diagnostic log and a second index record corresponding to the diagnostic log; S3. Record the trigger time of the hierarchical network diagnosis, add an association identifier to the operation log within a preset time range before and after the trigger time, and mark it as a fault window log; The association identifier is used to associate the operation log and the diagnostic log; S4. When network recovery is detected, the diagnostic log and the fault window log are uploaded to the cloud based on the first index record and the second index record.
2. The method for diagnosing and troubleshooting terminal network anomalies according to claim 1, characterized in that, Step S0 is included before step S1: A log management information area, an index record area, and a log text area are generated in the terminal's memory, and the write positions for the index record area and the log text area are generated in the log management information area. Step S1 specifically includes: Obtain runtime information and generate corresponding runtime logs, generate a first index record based on the runtime logs; generate a write position based on the log management information area, write the runtime logs into the log body area, and generate a first index record in the index record area; Step S2 specifically includes: Based on the triggering of the terminal network anomaly, a hierarchical network diagnosis is performed on the terminal to locate the level of the network anomaly, and a corresponding diagnostic log and a second index record corresponding to the diagnostic log are generated; the second index record is written to a preset priority position in the index record area with high priority.
3. The method for diagnosing and troubleshooting terminal network anomalies according to claim 2, characterized in that, Step S0 further includes: In the memory, the log management information area is stored using at least two redundant copies; The integrity of the redundant copies is verified and the redundant copies that pass the verification are marked as valid copies. The write positions of the index record area and the log text area are generated based on the valid copies.
4. The method for diagnosing and troubleshooting terminal network anomalies according to claim 2, characterized in that, Step S0 further includes: When the write position of the index record area reaches the end, the write position cycles back to the beginning position of the index record area and overwrites the earliest generated index record.
5. The method for diagnosing and troubleshooting terminal network anomalies according to claim 1, characterized in that, Step S2, which involves performing layered network diagnostics on the terminal, specifically includes: The system reads whether the link in the terminal's status register is established. If the link in the status register is disconnected, it is determined to be a physical layer fault, and a corresponding diagnostic log is generated. The system counts the packet loss rate and round-trip time of the terminal. If the packet loss rate exceeds a preset threshold or the round-trip time exceeds a preset delay, it is determined to be a network layer fault, and a corresponding diagnostic log is generated. A TCP connection is established with the target server. If the TCP connection is abnormally disconnected or the handshake delay exceeds a preset threshold, it is determined to be a transport layer fault, and a corresponding diagnostic log is generated. The system detects the response status of the application protocol. When the response status is abnormal, it is determined to be an application layer fault, and a corresponding diagnostic log is generated.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the following steps: S1. Obtain running information and generate corresponding running logs, and generate a first index record based on the running logs; S2. Based on the triggering of the terminal network anomaly, perform hierarchical network diagnosis on the terminal and locate the level of the network anomaly, and generate a corresponding diagnostic log and a second index record corresponding to the diagnostic log; the association identifier is used to associate the operation log and the diagnostic log. S3. Record the trigger time of the hierarchical network diagnosis, add an association identifier to the operation log within a preset time range before and after the trigger time, and mark it as a fault window log; S4. When network recovery is detected, the diagnostic log and the fault window log are uploaded to the cloud based on the first index record and the second index record.
7. A computer-readable storage medium according to claim 6, characterized in that, Step S0 is included before step S1: A log management information area, an index record area, and a log text area are generated in the terminal's memory, and the write positions for the index record area and the log text area are generated in the log management information area. Step S1 specifically includes: Obtain runtime information and generate corresponding runtime logs, generate a first index record based on the runtime logs; generate a write position based on the log management information area, write the runtime logs into the log body area, and generate a first index record in the index record area; Step S2 specifically includes: Based on the triggering of the terminal network anomaly, a hierarchical network diagnosis is performed on the terminal to locate the level of the network anomaly, and a corresponding diagnostic log and a second index record corresponding to the diagnostic log are generated; the second index record is written to a preset priority position in the index record area with high priority.
8. A computer-readable storage medium according to claim 7, characterized in that, Step S0 further includes: The log management information area is stored in the memory with at least two redundant copies; The integrity of the redundant copies is verified and the redundant copies that pass the verification are marked as valid copies. The write positions of the index record area and the log text area are generated based on the valid copies.
9. A computer-readable storage medium according to claim 7, characterized in that, Step S0 further includes: When the write position of the index record area reaches the end of the index record area, the write position wraps back to the beginning of the index record area and overwrites the earliest generated index record.
10. A computer-readable storage medium according to claim 6, characterized in that, Step S2, which involves performing layered network diagnostics on the terminal, specifically includes: The system reads whether the link in the terminal's status register is established. If the link in the status register is disconnected, it is determined to be a physical layer fault, and a corresponding diagnostic log is generated. The system counts the packet loss rate and round-trip time of the terminal. If the packet loss rate exceeds a preset threshold or the round-trip time exceeds a preset delay, it is determined to be a network layer fault, and a corresponding diagnostic log is generated. A TCP connection is established with the target server. If the TCP connection is abnormally disconnected or the handshake delay exceeds a preset threshold, it is determined to be a transport layer fault, and a corresponding diagnostic log is generated. The system detects the response status of the application protocol. When the response status is abnormal, it is determined to be an application layer fault, and a corresponding diagnostic log is generated.