Equipment online state statistical method and system based on distributed soft bus, terminal and storage medium
By using a device online status statistics method based on a distributed soft bus, the system can monitor and count the online and offline events of a large number of devices in real time. This solves the shortcomings of existing device status statistics, achieves high-precision and automated frequency statistics of device connection behavior, and improves the reliability of system stability assessment and the reproducibility of test verification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 深圳开鸿数字产业发展有限公司
- Filing Date
- 2025-12-25
- Publication Date
- 2026-04-17
AI Technical Summary
Existing technologies cannot efficiently and accurately count the number of times devices are online and offline in large-scale device networking environments. They lack system-level device discovery and status change callback mechanisms, cannot capture device online and offline events in real time and accurately, and have performance bottlenecks and insufficient access control issues in long-term testing with thousands of devices.
The device online status statistics method based on distributed soft bus obtains permissions from the permission management framework, initializes the soft bus communication service, registers callback functions for listening to node status changes, constructs a mapping table from network identifier to network address, and generates status change records containing timestamps to achieve real-time listening and counting of device online and offline events.
It enables high-precision, automated statistical analysis of the frequency of device connection behaviors across thousands of devices, providing a reliable data foundation for system stability assessment. It breaks through the real-time and scale bottlenecks of traditional monitoring methods, constructs a unified device connection view across network types, and improves the reproducibility and data traceability of testing and verification.
Smart Images

Figure CN121887855A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method, system, terminal, and computer-readable storage medium for online device status statistics based on a distributed soft bus. Background Technology
[0002] With the rapid development of the Internet of Things (IoT) and distributed operating systems, large-scale device collaboration has become the norm. Open-source Harmony and OpenEuler, as distributed operating systems designed for all scenarios, prioritize device interconnectivity and collaboration, especially in smart homes, industrial IoT, and connected vehicle scenarios, where hundreds or even thousands of devices often need to network simultaneously. In such large-scale distributed systems, the stability and frequency of dynamic changes in the network status (online / offline) of devices are core indicators for measuring overall system reliability and service quality.
[0003] Currently, in large-scale device networking environments, there is a lack of dedicated testing tools capable of efficiently, accurately, and over extended periods counting the number of times devices are online and offline. Traditional methods typically rely on system log analysis or simple connectivity checks, which are insufficient to handle scenarios where devices frequently and dynamically join or leave the network, and have the following shortcomings: Limited monitoring dimensions: It is impossible to cover the status of devices with multiple connection methods such as WLAN, Ethernet, and BLE simultaneously through a unified framework, resulting in monitoring blind spots.
[0004] Event capture lag: The lack of a system-level device discovery and state change callback mechanism makes it impossible to capture device online and offline events in real time and accurately.
[0005] Insufficient statistical accuracy: The lack of continuous mapping and management between device network IDs and physical addresses (such as IP addresses) can lead to statistical errors or failure to correlate data in large-scale scenarios or scenarios with dynamic changes in network topology.
[0006] Weak support for large-scale deployments: In long-term testing with thousands of devices, existing tools have bottlenecks in performance, memory management, and concurrent event processing, making it difficult to guarantee stability and data integrity during long-term operation.
[0007] Lack of permissions and security: The system does not fully integrate the permission management mechanism of the distributed system (such as AccessToken), which cannot ensure that the necessary device management and data synchronization permissions are obtained, resulting in limited monitoring.
[0008] Therefore, existing technologies still need to be improved and developed. Summary of the Invention
[0009] The main objective of this invention is to provide a method, system, terminal, and computer-readable storage medium for online status statistics of devices based on a distributed soft bus, aiming to solve the problem in the prior art that it is impossible to perform real-time, accurate monitoring and count of online and offline events of HarmonyOS and Euler devices in large-scale networks (such as thousands of devices).
[0010] To achieve the above objectives, the present invention provides a method for statistical analysis of the online status of devices based on a distributed soft bus, the method comprising the following steps: Based on a distributed operating system-based permission management framework, it obtains the necessary permissions for cross-device discovery, status monitoring, and data access, and initializes the soft bus communication service. Call the local network node management interface of the soft bus, register a callback function to listen for node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework; When starting the listening process, the network identifiers of all currently online devices are obtained, and the network addresses corresponding to the online devices are resolved. A mapping table from network identifiers to network addresses is then constructed and dynamically maintained. When the online or offline event of the target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing timestamp, network address and event type is generated. Based on the network address and event type in the status change record, the online and offline events occurring at the same network address are cumulatively counted to obtain the total number of online and offline events for each network address. The total number of times each network address goes online and offline, as well as the total number of all events, are summarized in a predetermined format and output as a readable statistical report.
[0011] Optionally, the device online status statistics method based on a distributed soft bus, wherein the permission management framework based on a distributed operating system acquires the necessary permissions for cross-device discovery, status monitoring, and data access, and initializes the soft bus communication service, specifically includes: By calling the permission request interface, the system requests and obtains distributed data management permissions for cross-device data synchronization, soft bus center access permissions for accessing soft bus core services, and device management service access permissions for managing network nodes from the permission management framework of the distributed operating system. After successfully obtaining permissions, initialize the distributed soft bus communication service to establish the basic communication environment for device discovery and status monitoring.
[0012] Optionally, the method for statistically analyzing the online status of devices based on a distributed soft bus, wherein calling the local network node management interface of the soft bus and registering a callback function for listening to node status changes, so that the management device receives device online and device offline events actively reported by the soft bus framework, specifically includes: Call the local network node management interface of the soft bus to initialize the lightweight network subsystem; During initialization, a callback function for monitoring node state changes is registered. The callback function includes at least a first callback function for responding to a device online event and a second callback function for responding to a device offline event. The parameters of the callback function include at least the network identifier of the node that triggered the event. The callback function enables the management device to receive event notifications proactively reported by the soft bus framework when it detects a change in the state of a network node.
[0013] Optionally, the method for statistically analyzing the online status of devices based on a distributed soft bus, wherein, upon initiating monitoring, the method acquires the network identifiers of all currently online devices, parses the network addresses corresponding to the online devices, and constructs and dynamically maintains a mapping table from network identifiers to network addresses, specifically including: When starting the listener, the device information retrieval interface is called to obtain a list of all currently online devices; The network identifier and corresponding network protocol address of each online device are parsed from the list information; A mapping table between network identifiers and addresses is constructed using the network identifier as the key and the network protocol address as the value. During subsequent operation, the mapping table is dynamically added, deleted, or updated based on the monitored device online or offline events.
[0014] Optionally, the method for statistically analyzing the online status of devices based on a distributed soft bus, wherein when an online or offline event of a target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing a timestamp, network address, and event type is generated, specifically including: When the online event of the target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is determined or recorded according to the mapping table. The event type is marked as online, and an online status change record is generated. When the offline event of the target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is queried according to the mapping table. The event type is marked as offline, and an offline status change record is generated. Each of the aforementioned status change records includes a timestamp, network address, and event type field.
[0015] Optionally, the method for statistically analyzing the online status of devices based on a distributed soft bus, wherein the step of accumulating and counting online and offline events occurring at the same network address according to the network address and event type in the status change record to obtain the total number of online and offline events corresponding to each network address, specifically includes: Create and maintain a first statistical mapping table and a second statistical mapping table. The first statistical mapping table is used to accumulate the number of online times using network address as the index, and the second statistical mapping table is used to accumulate the number of offline times using network address as the index. For each generated status change record, based on whether the event type is online or offline, the count value of the network address corresponding to the status change record in the first statistical mapping table or the second statistical mapping table is incremented by one to obtain the total number of online and offline times for each network address.
[0016] Optionally, the method for statistically analyzing the online status of devices based on a distributed soft bus, wherein summarizing and outputting the total number of online and offline times for each network address, as well as the total number of all events, in a predetermined format as a readable statistical report, specifically includes: After reaching the preset monitoring period or receiving a stop command, the statistical results of all network addresses are traversed and summarized. The summarized results are organized according to a predetermined format to generate a statistical report containing information on the total number of online times, the total number of offline times, and the total number of all events for each network address. The statistical report is output to the console for display and to the specified log file.
[0017] Furthermore, to achieve the above objectives, the present invention also provides a device online status statistics system based on a distributed soft bus, wherein the device online status statistics system based on a distributed soft bus includes: The permission initialization module is used by the permission management framework based on the distributed operating system to obtain the necessary permissions for cross-device discovery, status monitoring and data access, and to initialize the soft bus communication service. The function registration module is used to call the local network node management interface of the soft bus, register the callback function for listening to node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework. The relationship table construction module is used to obtain the network identifiers of all currently online devices when starting listening, parse the network addresses corresponding to the online devices, and build and dynamically maintain a mapping relationship table from network identifiers to network addresses; The device status monitoring module is used to determine the network address of the target device according to the event type and the mapping relationship table when the online or offline event of the target device is detected through the callback function, and generate a status change record containing timestamp, network address and event type. The data statistics module is used to accumulate and count the online and offline events that occur at the same network address based on the network address and event type in the status change record, so as to obtain the total number of online events and the total number of offline events for each network address. The report output module is used to summarize and output a readable statistical report based on a predetermined format the total number of times each network address goes online and offline, as well as the total number of all events.
[0018] Furthermore, to achieve the above objectives, the present invention also provides a terminal, wherein the terminal includes: a memory, a processor, and a device online status statistics program based on a distributed soft bus stored in the memory and executable on the processor, wherein when the device online status statistics program based on a distributed soft bus is executed by the processor, it implements the steps of the device online status statistics method based on a distributed soft bus as described above.
[0019] Furthermore, to achieve the above objectives, the present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a device online status statistics program based on a distributed soft bus, and when the device online status statistics program based on a distributed soft bus is executed by a processor, it implements the steps of the device online status statistics method based on a distributed soft bus as described above.
[0020] In this invention, a permission management framework based on a distributed operating system is used to acquire the necessary permissions for cross-device discovery, status monitoring, and data access, and to initialize the soft bus communication service. The local network node management interface of the soft bus is called to register a callback function for monitoring node status changes, enabling the management device to receive device online and offline events actively reported by the soft bus framework. Upon initiating monitoring, the network identifiers of all currently online devices are obtained, and the network addresses corresponding to the online devices are parsed. A mapping table from network identifiers to network addresses is constructed and dynamically maintained. When an online or offline event of a target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing a timestamp, network address, and event type is generated. Based on the network address and event type in the status change record, online and offline events occurring at the same network address are cumulatively counted to obtain the total number of online and offline events for each network address. The total number of online and offline events for each network address, along with the total number of all events, are summarized in a predetermined format and output as a readable statistical report. This invention utilizes the node management and event callback mechanism of a distributed soft bus framework to capture every online and offline event of each device in real time and accurately. It also enables precise and automated counting of device connection frequency on a scale of thousands of devices, providing a reliable data foundation for quantitatively evaluating system stability. Attached Figure Description
[0021] Figure 1 This is a flowchart of a preferred embodiment of the device online status statistics method based on a distributed soft bus according to the present invention; Figure 2 This is a structural diagram of a preferred embodiment of the device online status statistics system based on a distributed soft bus according to the present invention; Figure 3 This is a structural diagram of a preferred embodiment of the terminal of the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this invention clearer and more explicit, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0023] The preferred embodiment of the device online status statistics method based on a distributed soft bus described in this invention, such as... Figure 1 As shown, the online status statistics method for devices based on a distributed soft bus includes the following steps: Step S10: Based on the permission management framework of the distributed operating system, obtain the necessary permissions for cross-device discovery, status monitoring and data access, and initialize the soft bus communication service.
[0024] Specifically, by calling the permission request interface (e.g., ToolAddPermission()), the system requests and obtains distributed data management permissions for cross-device data synchronization, soft bus center access permissions for accessing the soft bus core service, and device management service access permissions for managing network nodes from the distributed operating system's permission management framework. After successfully obtaining permissions, the distributed soft bus communication service is initialized, establishing the basic communication environment for device discovery and status monitoring. For example, in the open-source HarmonyOS environment, permissions such as ohos.permission.DISTRIBUTED_DATASYNC need to be requested to ensure that the tool can legally discover other devices in the network and monitor their status.
[0025] Step S20: Call the local network node management interface of the soft bus, register the callback function for listening to node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework.
[0026] Specifically, the local network node management interface of the soft bus (e.g., BC_InitLNN()) is invoked to initialize the lightweight network subsystem (LNN). During initialization, callback functions for listening to node state changes (e.g., OnNodeOnline and OnNodeOffline) are registered. These callback functions include at least a first callback function for responding to device online events and a second callback function for responding to device offline events. The parameters of these callback functions at least include the network identifier of the node that triggered the event. Through these callback functions, the management device receives event notifications actively reported by the soft bus framework when it detects changes in network node state. For example, after registering the OnNodeOnline(NodeID) callback, when a new device joins the network, the soft bus framework automatically calls this function and passes the new device's unique network identifier (NodeID) to this tool.
[0027] Step S30: When starting the listening, obtain the network identifiers of all currently online devices, parse the network addresses corresponding to the online devices, and build and dynamically maintain a mapping table from network identifiers to network addresses.
[0028] Specifically, upon initiating monitoring, a list of all currently online devices is retrieved by calling a device information acquisition interface (e.g., BC_GetOnlineDeviceInfo()). The network identifier and corresponding network protocol address (e.g., IP address) of each online device are parsed from this list. A mapping table (e.g., NetworkIdToIpMap) is constructed using the network identifier as the key and the network protocol address as the value. During subsequent operation, the mapping table is dynamically updated, deleted, or modified based on detected device online or offline events to maintain consistency with the real-time network status. For example, if device A's network identifier is "Device_A_HashID" and its parsed IP address is "192.168.1.101", then a key-value pair "Device_A_HashID" -> "192.168.1.101" is created in the mapping table.
[0029] Step S40: When the online or offline event of the target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping relationship table, and a status change record containing timestamp, network address and event type is generated.
[0030] Specifically, when an online event of a target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is determined or recorded according to the mapping table. The event type is marked as online, and an online status change record is generated. When an offline event of a target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is queried according to the mapping table. The event type is marked as offline, and an offline status change record is generated. Each status change record contains a timestamp, network address, and event type field. For example, after receiving the OnNodeOnline(Device_A_HashID) event, the mapping table is queried to obtain the IP "192.168.1.101", the record "[2025-10-27 10:00:00, 192.168.1.101, ONLINE]" is generated and written to the log file.
[0031] Step S50: Based on the network address and event type in the status change record, accumulate the online and offline events occurring at the same network address to obtain the total number of online and offline events for each network address.
[0032] Specifically, a first statistical mapping table and a second statistical mapping table (e.g., Online_data_map and Offline_data_map) are created and maintained. The first statistical mapping table is used to accumulate the number of online events indexed by network address, and the second statistical mapping table is used to accumulate the number of offline events indexed by network address. For each generated status change record, depending on whether the event type is online or offline, the count value of the network address corresponding to the status change record in the first or second statistical mapping table is incremented by one to obtain the total number of online events and the total number of offline events for each network address. For example, when processing the online record in the above example, the key "192.168.1.101" is searched in Online_data_map. If it exists, its value (current online event count) is incremented by 1; if it does not exist, the key is created and its value is set to 1.
[0033] Step S60: Summarize the total number of times each network address goes online and offline, as well as the total number of all events, according to a predetermined format and output them as a readable statistical report.
[0034] Specifically, upon reaching a preset monitoring period (e.g., after reaching a user-preset monitoring duration, such as 1 hour) or receiving a stop command, the system iterates through and summarizes the statistical results of all network addresses; organizes the summarized results according to a predetermined format to generate a statistical report containing information on the total number of online events, total number of offline events, and total number of events for each network address; and outputs the statistical report to the console for display and to a specified log file. For example, calling the PrintMapStatistics() function generates a report line similar to "IP: 192.168.1.101, Online: 15, Offline: 14", and summarizes and outputs "Total Online Events: 1500, Total Offline Events: 1498".
[0035] This invention can be implemented as a software tool running on a management device (such as a PC or server), which needs to be connected to a target distributed network (such as a test network consisting of 1000 HarmonyOS or Euler devices). After startup, the tool automatically executes the process described in steps S10 to S60. Users can set the monitoring duration, log path, etc., through configuration files or command-line parameters. During operation, the tool continuously listens for events, updates statistics, and automatically generates a report upon completion. This tool is particularly suitable for scenarios such as long-term stability stress testing of distributed operating systems and network reliability assessment.
[0036] This invention can efficiently and accurately track the online / offline behavior of a large number of devices (e.g., 1000 devices) within a specified time period, making it suitable for distributed environment testing on HarmonyOS and Euler operating systems. Throughout the monitoring cycle, the tool automatically collects timestamped log information, ultimately generating statistical reports and outputting them to log files and the console, facilitating subsequent analysis of device connection stability and network reliability. The overall process is highly automated, resource-efficient, and highly scalable, making it suitable for long-term automated stability testing scenarios.
[0037] The technical effects that this invention can bring are as follows: (1) Achieved high-precision and automated statistics on the online status of large-scale distributed network devices: By utilizing the node management and event callback mechanism of the distributed soft bus framework, it is possible to capture every online and offline event of each device in real time and accurately (instead of polling), and achieve accurate and automated counting of device connection behavior frequency on a scale of thousands of devices, providing a reliable data foundation for quantitative evaluation of system stability.
[0038] (2) Breakthrough in real-time performance and scale of traditional monitoring methods: Compared with traditional methods that rely on log analysis or active detection, this invention achieves millisecond-level state change perception through a system-level "event-driven" model, with no delay and no omissions. At the same time, its architecture design can effectively support concurrent event processing and long-term stable operation of thousands of devices, solving the problems of insufficient monitoring performance and excessive resource consumption in large-scale scenarios.
[0039] (3) Provides a complete device connection view that is cross-network type and unified abstraction: By integrating and uniformly managing device discovery and status under multiple connection methods such as WLAN, Ethernet, and BLE, this invention constructs a global mapping view from network identifier to network address, which makes statistics no longer affected by the differences in underlying physical connection methods and can comprehensively and consistently reflect the overall connection status of the entire distributed network.
[0040] (4) Enhanced reproducibility and data traceability of the testing and verification process: This invention automatically records each state change event with a timestamp and generates a structured statistical report. This not only makes the test results reproducible, but also provides a detailed time-series data chain for post-event analysis of the root causes of problems such as abnormal device shutdown and network fluctuations, which greatly improves the efficiency of fault diagnosis and performance analysis.
[0041] (5) Improved integration and ease of use of distributed system testing tools: This invention encapsulates complex functions such as permission application, service initialization, event listening, data statistics and output into a complete tool or process. Users only need to configure simple monitoring parameters to start long-term automated testing, which reduces the technical threshold and operational complexity of conducting large-scale device stability testing.
[0042] Furthermore, such as Figure 2 As shown, based on the above-described method for online device status statistics using a distributed soft bus, this invention also provides a system for online device status statistics using a distributed soft bus, wherein the system includes: The permission initialization module 51 is used by the permission management framework based on the distributed operating system to obtain the necessary permissions for cross-device discovery, status monitoring and data access, and to initialize the soft bus communication service. Function registration module 52 is used to call the local network node management interface of the soft bus, register the callback function for listening to node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework. The relationship table construction module 53 is used to obtain the network identifiers of all currently online devices when starting the listening, and parse the network addresses corresponding to the online devices to build and dynamically maintain a mapping relationship table from network identifiers to network addresses; The device status monitoring module 54 is used to determine the network address of the target device according to the event type and the mapping relationship table when the online or offline event of the target device is detected through the callback function, and generate a status change record containing timestamp, network address and event type. The data statistics module 55 is used to accumulate and count the online and offline events that occur at the same network address according to the network address and event type in the status change record, so as to obtain the total number of online events and the total number of offline events for each network address. The report output module 56 is used to summarize and output a readable statistical report in a predetermined format the total number of times each network address goes online and offline, as well as the total number of all events, according to the statistics.
[0043] Furthermore, such as Figure 3 As shown, based on the above-mentioned online status statistics method and system for devices based on distributed soft bus, the present invention also provides a terminal, which includes a processor 10, a memory 20 and a display 30. Figure 3 Only some of the terminal components are shown; however, it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0044] In some embodiments, the memory 20 may be an internal storage unit of the terminal, such as a hard disk or memory. In other embodiments, the memory 20 may be an external storage device of the terminal, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc. Further, the memory 20 may include both internal and external storage devices. The memory 20 is used to store application software and various types of data installed on the terminal, such as the program code installed on the terminal. The memory 20 can also be used to temporarily store data that has been output or will be output. In one embodiment, the memory 20 stores a device online status statistics program 40 based on a distributed soft bus, which can be executed by the processor 10 to implement the device online status statistics method based on a distributed soft bus in this application.
[0045] In some embodiments, the processor 10 may be a central processing unit (CPU), a microprocessor, or other data processing chip, used to run program code stored in the memory 20 or process data, such as executing the device online status statistics method based on the distributed soft bus.
[0046] In some embodiments, the display 30 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen. The display 30 is used to display information on the terminal and to display a visual user interface. The terminal's processor 10, memory 20, and display 30 communicate with each other via a system bus.
[0047] In one embodiment, when the processor 10 executes the device online status statistics program 40 based on the distributed soft bus in the memory 20, the following steps are performed: Based on a distributed operating system-based permission management framework, it obtains the necessary permissions for cross-device discovery, status monitoring, and data access, and initializes the soft bus communication service. Call the local network node management interface of the soft bus, register a callback function to listen for node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework; When starting the listening process, the network identifiers of all currently online devices are obtained, and the network addresses corresponding to the online devices are resolved. A mapping table from network identifiers to network addresses is then constructed and dynamically maintained. When the online or offline event of the target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing timestamp, network address and event type is generated. Based on the network address and event type in the status change record, the online and offline events occurring at the same network address are cumulatively counted to obtain the total number of online and offline events for each network address. The total number of times each network address goes online and offline, as well as the total number of all events, are summarized in a predetermined format and output as a readable statistical report.
[0048] The aforementioned permission management framework based on a distributed operating system acquires the necessary permissions for cross-device discovery, status monitoring, and data access, and initializes the soft bus communication service, specifically including: By calling the permission request interface, the system requests and obtains distributed data management permissions for cross-device data synchronization, soft bus center access permissions for accessing soft bus core services, and device management service access permissions for managing network nodes from the permission management framework of the distributed operating system. After successfully obtaining permissions, initialize the distributed soft bus communication service to establish the basic communication environment for device discovery and status monitoring.
[0049] Specifically, the step of calling the local network node management interface of the soft bus and registering a callback function for listening to node status changes, enabling the management device to receive device online and offline events actively reported by the soft bus framework, includes: Call the local network node management interface of the soft bus to initialize the lightweight network subsystem; During initialization, a callback function for monitoring node state changes is registered. The callback function includes at least a first callback function for responding to a device online event and a second callback function for responding to a device offline event. The parameters of the callback function include at least the network identifier of the node that triggered the event. The callback function enables the management device to receive event notifications proactively reported by the soft bus framework when it detects a change in the state of a network node.
[0050] Specifically, upon initiating monitoring, the process of obtaining the network identifiers of all currently online devices, resolving the network addresses corresponding to the online devices, and constructing and dynamically maintaining a mapping table from network identifiers to network addresses includes: When starting the listener, the device information retrieval interface is called to obtain a list of all currently online devices; The network identifier and corresponding network protocol address of each online device are parsed from the list information; A mapping table between network identifiers and addresses is constructed using the network identifier as the key and the network protocol address as the value. During subsequent operation, the mapping table is dynamically added, deleted, or updated based on the monitored device online or offline events.
[0051] Specifically, when the online or offline event of the target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing a timestamp, network address, and event type is generated, including: When the online event of the target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is determined or recorded according to the mapping table. The event type is marked as online, and an online status change record is generated. When the offline event of the target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is queried according to the mapping table. The event type is marked as offline, and an offline status change record is generated. Each of the aforementioned status change records includes a timestamp, network address, and event type field.
[0052] Specifically, the step of accumulating and counting online and offline events occurring at the same network address based on the network address and event type in the status change record to obtain the total number of online and offline events for each network address includes: Create and maintain a first statistical mapping table and a second statistical mapping table. The first statistical mapping table is used to accumulate the number of online times using network address as the index, and the second statistical mapping table is used to accumulate the number of offline times using network address as the index. For each generated status change record, based on whether the event type is online or offline, the count value of the network address corresponding to the status change record in the first statistical mapping table or the second statistical mapping table is incremented by one to obtain the total number of online and offline times for each network address.
[0053] The process of summarizing and outputting a readable statistical report, which includes the total number of online and offline times for each network address and the total number of all events, according to a predetermined format, specifically includes: After reaching the preset monitoring period or receiving a stop command, the statistical results of all network addresses are traversed and summarized. The summarized results are organized according to a predetermined format to generate a statistical report containing information on the total number of online times, the total number of offline times, and the total number of all events for each network address. The statistical report is output to the console for display and to the specified log file.
[0054] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a device online status statistics program based on a distributed soft bus, and the device online status statistics program based on a distributed soft bus, when executed by a processor, implements the steps of the device online status statistics method based on a distributed soft bus as described above.
[0055] In summary, this invention provides a method, system, terminal, and computer-readable storage medium for device online status statistics based on a distributed soft bus. The method includes: acquiring necessary permissions for cross-device discovery, status monitoring, and data access based on a distributed operating system's permission management framework, and initializing the soft bus communication service; calling the local network node management interface of the soft bus, registering callback functions for node status change monitoring, enabling the management device to receive device online and offline events actively reported by the soft bus framework; and, upon initiating monitoring, obtaining the network identifiers of all currently online devices, resolving the network addresses corresponding to the online devices, and constructing and dynamically maintaining a network identifier for all devices online. A mapping table between network identifiers and network addresses is established. When an online or offline event of a target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing a timestamp, network address, and event type is generated. Based on the network address and event type in the status change record, online and offline events occurring at the same network address are cumulatively counted to obtain the total number of online and offline events for each network address. The total number of online and offline events for each network address, as well as the total number of all events, are summarized in a predetermined format and output as a readable statistical report. This invention, by utilizing the node management and event callback mechanism of a distributed soft bus framework, can capture every online and offline event of each device in real time and accurately, and achieve precise and automated counting of device connection behavior frequency at the scale of thousands of devices, providing a reliable data foundation for quantitatively evaluating system stability.
[0056] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal that includes that element.
[0057] Of course, those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware (such as a processor, controller, etc.). The program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The computer-readable storage medium can be a memory, magnetic disk, optical disk, etc.
[0058] It should be understood that the application of the present invention is not limited to the examples above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A method for online status statistics of devices based on a distributed soft bus, characterized in that, The method for statistical analysis of device online status based on distributed soft bus includes: Based on a distributed operating system-based permission management framework, it obtains the necessary permissions for cross-device discovery, status monitoring, and data access, and initializes the soft bus communication service. Call the local network node management interface of the soft bus, register a callback function to listen for node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework; When starting the listening process, the network identifiers of all currently online devices are obtained, and the network addresses corresponding to the online devices are resolved. A mapping table from network identifiers to network addresses is then constructed and dynamically maintained. When the online or offline event of the target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing timestamp, network address and event type is generated. Based on the network address and event type in the status change record, the online and offline events occurring at the same network address are cumulatively counted to obtain the total number of online and offline events for each network address. The total number of times each network address goes online and offline, as well as the total number of all events, are summarized in a predetermined format and output as a readable statistical report.
2. The method for online status statistics of devices based on a distributed soft bus according to claim 1, characterized in that, The permission management framework based on the distributed operating system acquires the necessary permissions for cross-device discovery, status monitoring, and data access, and initializes the soft bus communication service, specifically including: By calling the permission request interface, the system requests and obtains distributed data management permissions for cross-device data synchronization, soft bus center access permissions for accessing soft bus core services, and device management service access permissions for managing network nodes from the permission management framework of the distributed operating system. After successfully obtaining permissions, initialize the distributed soft bus communication service to establish the basic communication environment for device discovery and status monitoring.
3. The method for online status statistics of devices based on a distributed soft bus according to claim 1, characterized in that, The process of calling the local network node management interface of the soft bus and registering a callback function for listening to node status changes enables the management device to receive device online and offline events actively reported by the soft bus framework. Specifically, this includes: Call the local network node management interface of the soft bus to initialize the lightweight network subsystem; During initialization, a callback function for monitoring node state changes is registered. The callback function includes at least a first callback function for responding to a device online event and a second callback function for responding to a device offline event. The parameters of the callback function include at least the network identifier of the node that triggered the event. The callback function enables the management device to receive event notifications proactively reported by the soft bus framework when it detects a change in the state of a network node.
4. The method for online status statistics of devices based on a distributed soft bus according to claim 1, characterized in that, When starting the monitoring process, the network identifiers of all currently online devices are obtained, and the network addresses corresponding to the online devices are parsed. A mapping table from network identifiers to network addresses is constructed and dynamically maintained, specifically including: When starting the listener, the device information retrieval interface is called to obtain a list of all currently online devices; The network identifier and corresponding network protocol address of each online device are parsed from the list information; A mapping table between network identifiers and addresses is constructed using the network identifier as the key and the network protocol address as the value. During subsequent operation, the mapping table is dynamically added, deleted, or updated based on the monitored device online or offline events.
5. The method for online status statistics of devices based on a distributed soft bus according to claim 1, characterized in that, When the online or offline event of the target device is detected through the callback function, the network address of the target device is determined according to the event type and the mapping table, and a status change record containing a timestamp, network address, and event type is generated, specifically including: When the online event of the target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is determined or recorded according to the mapping table. The event type is marked as online, and an online status change record is generated. When the offline event of the target device is detected through the callback function, the timestamp of the event is recorded, and the network address of the target device is queried according to the mapping table. The event type is marked as offline, and an offline status change record is generated. Each of the aforementioned status change records includes a timestamp, network address, and event type field.
6. The method for online status statistics of devices based on a distributed soft bus according to claim 5, characterized in that, The step involves cumulatively counting online and offline events occurring at the same network address based on the network address and event type in the status change record, to obtain the total number of online and offline events for each network address. Specifically, this includes: Create and maintain a first statistical mapping table and a second statistical mapping table. The first statistical mapping table is used to accumulate the number of online times indexed by network address, and the second statistical mapping table is used to accumulate the number of offline times indexed by network address. For each generated status change record, based on whether the event type is online or offline, the count value of the network address corresponding to the status change record in the first statistical mapping table or the second statistical mapping table is incremented by one to obtain the total number of online and offline times for each network address.
7. The method for online status statistics of devices based on a distributed soft bus according to claim 6, characterized in that, The process involves summarizing and outputting a readable statistical report, based on a predetermined format, the total number of online and offline times for each network address, and the total number of all events. Specifically, this includes: After reaching the preset monitoring period or receiving a stop command, the statistical results of all network addresses are traversed and summarized. The summarized results are organized according to a predetermined format to generate a statistical report containing information on the total number of online times, the total number of offline times, and the total number of all events for each network address. The statistical report is output to the console for display and to the specified log file.
8. A device online status statistics system based on a distributed soft bus, characterized in that, The device online status statistics system based on distributed soft bus includes: The permission initialization module is used by the permission management framework based on the distributed operating system to obtain the necessary permissions for cross-device discovery, status monitoring and data access, and to initialize the soft bus communication service. The function registration module is used to call the local network node management interface of the soft bus, register the callback function for listening to node status changes, and enable the management device to receive device online and device offline events actively reported by the soft bus framework. The relationship table construction module is used to obtain the network identifiers of all currently online devices when starting listening, parse the network addresses corresponding to the online devices, and build and dynamically maintain a mapping relationship table from network identifiers to network addresses; The device status monitoring module is used to determine the network address of the target device according to the event type and the mapping relationship table when the online or offline event of the target device is detected through the callback function, and generate a status change record containing timestamp, network address and event type. The data statistics module is used to accumulate and count the online and offline events that occur at the same network address based on the network address and event type in the status change record, so as to obtain the total number of online events and the total number of offline events for each network address. The report output module is used to summarize and output a readable statistical report based on a predetermined format the total number of times each network address goes online and offline, as well as the total number of all events.
9. A terminal, characterized in that, The terminal includes: a memory, a processor, and a device online status statistics program based on a distributed soft bus stored in the memory and executable on the processor. When the device online status statistics program based on a distributed soft bus is executed by the processor, it implements the steps of the device online status statistics method based on a distributed soft bus as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a device online status statistics program based on a distributed soft bus, which, when executed by a processor, implements the steps of the device online status statistics method based on a distributed soft bus as described in any one of claims 1-7.