Traffic early warning method for micro-service interface and related device
By calculating the short-term and long-term average traffic ratios of the microservice interface and dynamically updating the threshold using the exponentially weighted moving average method, the reliability issues of existing traffic warning methods under the dynamic and unpredictable nature of traffic are resolved, and more accurate traffic warnings are achieved.
Patent Information
- Application Number
- CN202510933593.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-07
- Publication Date
- 2025-09-09
AI Technical Summary
Existing traffic warning methods are based on fixed thresholds and are difficult to adapt to the dynamic and unpredictable nature of traffic, resulting in wasted resources during peak hours or missed response opportunities during off-peak hours, and poor warning reliability.
By determining the traffic data at the current monitoring moment, combining the short-term and long-term historical traffic data to calculate the average traffic ratio, and using the exponentially weighted moving average method to dynamically update the traffic threshold, traffic early warning for the microservice interface is achieved.
Improves the reliability of traffic early warning, avoids false alarms and missed alarms, ensures that the system responds promptly to traffic changes, and maintains stability and performance.
Smart Images

Figure CN120614281A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a traffic early warning method and related device for a microservice interface. Background Art
[0002] With the rapid development of internet services and the continued rise in user demand, network traffic has become highly dynamic and unpredictable. The rapid growth in total traffic volume and the complex variations in traffic patterns, such as sudden peaks and periodic fluctuations, pose severe challenges to the stable operation of network systems. In this context, timely and accurate traffic early warning is crucial.
[0003] Currently, traffic warning methods mainly use fixed thresholds set based on current traffic data and historical data for warning.
[0004] However, traffic is dynamic and unpredictable. During peak hours, the current traffic data may reach the fixed threshold too early, triggering an early warning and resulting in unnecessary waste of resources. During off-peak hours, the current traffic data may not be sufficient to reach the fixed threshold in time to detect potential problems, thus missing the best time to respond. The traffic early warning method based on fixed thresholds is difficult to adapt to sudden changes in traffic, resulting in poor reliability of traffic early warning. Summary of the Invention
[0005] In view of the above problems, this application provides a traffic warning method and related devices for a microservice interface to improve the reliability of traffic warning. The specific solution is as follows:
[0006] The first aspect of the present application provides a traffic early warning method for a microservice interface, comprising:
[0007] Determine the current traffic data of the microservice interface at the current monitoring moment;
[0008] Obtaining first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, wherein the end time of the time period corresponding to the preset short-term window is consistent with the end time of the time period corresponding to the preset long-term window, and the length of the time period corresponding to the preset short-term window is less than the length of the time period corresponding to the preset long-term window;
[0009] determining an average flow rate ratio at the current monitoring moment based on the first historical flow data, the second historical flow data, and the current flow data at the current monitoring moment;
[0010] Based on the average traffic ratio and the current traffic threshold at the current monitoring time, a traffic warning is issued to the microservice interface;
[0011] Based on a preset smoothing factor and the average flow rate ratio at the current monitoring moment, the current flow rate threshold is updated using an exponentially weighted moving average method.
[0012] In a possible implementation, determining the average flow ratio at the current monitoring moment based on the first historical flow data, the second historical flow data, and the current flow data at the current monitoring moment includes:
[0013] Calculating the short-term average flow rate at the current monitoring moment based on the first historical flow rate data and the current flow rate data at the current monitoring moment;
[0014] Calculating the long-term average flow rate at the current monitoring moment based on the second historical flow rate data and the current flow rate data at the current monitoring moment;
[0015] The average flow rate ratio at the current monitoring moment is calculated based on the short-term average flow rate at the current monitoring moment and the long-term average flow rate at the current monitoring moment.
[0016] In a possible implementation, the process of determining the initial value of the current flow threshold includes:
[0017] Obtaining third historical traffic data for a preset historical monitoring time period, and calculating, based on the third historical traffic data, an average value and a standard deviation of average traffic ratios at each historical monitoring moment in the preset historical monitoring time period, wherein the preset historical monitoring time period is earlier than a time period corresponding to the preset short-term window and a time period corresponding to the preset long-term window;
[0018] An initial value of the current flow threshold is calculated based on the average value and the standard deviation of the average flow ratio at each of the historical monitoring moments.
[0019] In a possible implementation, performing a traffic warning on the microservice interface based on the average traffic ratio and the current traffic threshold at the current monitoring moment includes:
[0020] Determining whether the average flow rate ratio at the current monitoring moment is greater than the current flow threshold;
[0021] If the average flow rate at the current monitoring moment is greater than the current flow threshold, a flow warning is issued to the microservice interface.
[0022] In a possible implementation, after obtaining first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, the method further includes:
[0023] Preprocessing the first historical flow data, the second historical flow data, and the current flow threshold at the current monitoring moment respectively to obtain preprocessed first historical flow data, preprocessed second historical flow data, and preprocessed current flow data at the current monitoring moment;
[0024] The determining the average flow ratio at the current monitoring moment based on the first historical flow data, the second historical flow data, and the current flow data at the current monitoring moment includes:
[0025] Based on the preprocessed first historical flow data, the preprocessed second historical flow data and the preprocessed current flow data at the current monitoring moment, an average flow ratio at the current monitoring moment is determined.
[0026] A second aspect of the present application provides a traffic warning device for a microservice interface, comprising:
[0027] A first determining unit is used to determine the current traffic data of the microservice interface at the current monitoring moment;
[0028] an acquisition unit, configured to acquire first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, wherein an end time of the time period corresponding to the preset short-term window is consistent with an end time of the time period corresponding to the preset long-term window, and a length of the time period corresponding to the preset short-term window is less than a length of the time period corresponding to the preset long-term window;
[0029] a second determining unit, configured to determine an average flow rate ratio at the current monitoring moment based on the first historical flow rate data, the second historical flow rate data, and the current flow rate data at the current monitoring moment;
[0030] An early warning unit, configured to issue a traffic early warning to the microservice interface based on the average traffic ratio at the current monitoring moment and a current traffic threshold;
[0031] An updating unit is configured to update the current flow threshold by using an exponentially weighted moving average method based on a preset smoothing factor and the average flow ratio at the current monitoring moment.
[0032] In a possible implementation, the second determining unit includes:
[0033] a first calculation subunit, configured to calculate a short-term average flow rate at the current monitoring moment based on the first historical flow rate data and the current flow rate data at the current monitoring moment;
[0034] a second calculation subunit, configured to calculate the long-term average flow rate at the current monitoring moment based on the second historical flow rate data and the current flow rate data at the current monitoring moment;
[0035] The third calculation subunit is configured to calculate the average flow rate ratio at the current monitoring moment based on the short-term average flow rate at the current monitoring moment and the long-term average flow rate at the current monitoring moment.
[0036] In a third aspect, the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the traffic warning method for the microservice interface of the above-mentioned first aspect or any implementation method of the first aspect.
[0037] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0038] The memory is used to store computer programs;
[0039] The processor is used to execute the computer program so that the electronic device can implement the traffic early warning method of the microservice interface of the above-mentioned first aspect or any implementation method of the first aspect.
[0040] In a fifth aspect, the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the traffic warning method of the microservice interface of the first aspect or any implementation method of the first aspect.
[0041] By means of the above technical solution, the present application provides a traffic early warning method and related device for a microservice interface, the method comprising: determining the current traffic data of the microservice interface at the current monitoring moment; obtaining first historical traffic data of a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data of a time period corresponding to a preset long-term window before the current monitoring moment, wherein the end time of the time period corresponding to the preset short-term window is consistent with the end time of the time period corresponding to the preset long-term window, and the length of the time period corresponding to the preset short-term window is less than the length of the time period corresponding to the preset long-term window; a multi-dimensional data collection method provides a basis for subsequent dynamic analysis. Based on the first historical traffic data, the second historical traffic data, and the current traffic data at the current monitoring moment, an average traffic ratio at the current monitoring moment is determined; the average traffic ratio can reflect the short-term fluctuations and long-term trends of the traffic. Based on the average traffic ratio at the current monitoring moment and the current traffic threshold, a traffic early warning is issued for the microservice interface; based on the preset smoothing factor and the average traffic ratio at the current monitoring moment, the current traffic threshold is updated using the exponentially weighted moving average method, thereby automatically adjusting the threshold according to the actual changes in the traffic, making it closer to the current traffic conditions, facilitating more accurate judgment of whether the traffic is abnormal, avoiding false alarms and missed alarms, and thus improving the reliability of the traffic early warning. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.
[0043] Figure 1 A flow chart of a traffic warning method for a microservice interface provided in an embodiment of the present application;
[0044] Figure 2 A schematic diagram of the flow rate data at each monitoring time provided in an embodiment of the present application;
[0045] Figure 3 A schematic diagram of an average flow rate ratio and a current flow threshold provided in an embodiment of the present application;
[0046] Figure 4 A flowchart of a method for updating a current flow threshold provided in an embodiment of the present application;
[0047] Figure 5 A schematic diagram of the structure of a traffic warning device for a microservice interface provided in an embodiment of the present application;
[0048] Figure 6A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following describes the embodiments of the present application in conjunction with the accompanying drawings. The terms used in the implementation methods of the present application are only used to explain the specific embodiments of the present application and are not intended to limit the present application.
[0050] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0051] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0052] In order to improve the reliability of traffic warning, the present application provides a traffic warning method for a microservice interface. The traffic warning method for the microservice interface provided by the present application is further described in detail below in combination with the accompanying drawings and specific implementation methods.
[0053] Please see the attached Figure 1 , Figure 1 A flow chart of a traffic warning method for a microservice interface provided in an embodiment of the present application. The method may include the following steps:
[0054] Step S101: Determine the current traffic data of the microservice interface at the current monitoring moment.
[0055] In this application, the flow data collection of the microservice interface is a prerequisite for determining the current flow data at the current monitoring moment.
[0056] Specifically, you can continuously collect traffic data of microservice interfaces through monitoring tools, middleware, or custom logs. These traffic data usually include key indicators such as the number of requests per minute, response time, and error rate. For easier understanding, please refer to Figure 2 , Figure 2A line diagram of traffic data at each monitoring time provided in an embodiment of the present application. The horizontal axis of the line diagram represents each minute from June 1, 2024 to August 13, 2024, and the vertical axis of the line diagram represents the number of requests per minute. The following are several common methods for collecting traffic data:
[0057] Use monitoring tools such as Prometheus, which can collect metrics from microservices using configured scraping tasks. These metrics can include the number of API requests and response times. Prometheus can store this data in a time series database for easy query and analysis.
[0058] Middleware integration: In Spring Cloud microservices, you can use Spring AOP combined with libraries such as Micrometer to collect the number of requests and response times of the interface, and push this collected data regularly.
[0059] Link tracing tools: For example, OpenTelemetry, which can track the life cycle of each request, record the request path and performance indicators. This data can be used to analyze interface traffic and performance bottlenecks.
[0060] During the traffic data collection process, it is necessary to determine the traffic data at the current monitoring moment in real time. This can be obtained directly from the time series database. For example, using Prometheus's query language PromQL, you can query the number of requests per minute for a specific interface.
[0061] Step S102: Obtain the first historical traffic data of the time period corresponding to the preset short-term window before the current monitoring moment and the second historical traffic data of the time period corresponding to the preset long-term window before the current monitoring moment. The end time of the time period corresponding to the preset short-term window is consistent with the end time of the time period corresponding to the preset long-term window, and the length of the time period corresponding to the preset short-term window is less than the length of the time period corresponding to the preset long-term window.
[0062] It should be noted that the preset short-term window is a shorter time range, such as 5 minutes. It is used to observe the interface traffic in a shorter time period in order to quickly detect sudden traffic or anomalies. The preset long-term window is a longer time range, such as 60 minutes. It is used to observe the trend and stability of interface traffic over a longer period of time. The end time of the short-term window and the long-term window is consistent with the current monitoring time, that is, they both end at the current monitoring time. For example, assuming that the current monitoring time is 14:00, then both the short-term window and the long-term window will end at 13:59. Since the short-term window is shorter, its start time will be closer to the current monitoring time than the start time of the long-term window.
[0063] For ease of understanding, an example is given below: the current monitoring time is 14:00, the preset short-term window is 5 minutes, and the first historical traffic data of the time period corresponding to the preset short-term window before the current monitoring time is the first historical traffic data of 13:56-13:59; the preset long-term window is 60 minutes, and the second historical traffic data of the time period corresponding to the preset long-term window before the current monitoring time is the second historical traffic data of 13:01-13:59.
[0064] Furthermore, after obtaining the first historical traffic data of the time period corresponding to the preset short-term window before the current monitoring moment and the second historical traffic data of the time period corresponding to the preset long-term window before the current monitoring moment, the method may also include the following steps: preprocessing the first historical traffic data, the second historical traffic data and the current traffic threshold of the current monitoring moment respectively to obtain the preprocessed first historical traffic data, the preprocessed second historical traffic data and the preprocessed current traffic data of the current monitoring moment.
[0065] In actual detection and traffic data analysis, traffic data often has various problems, such as outliers and missing values. These data problems may affect subsequent analysis results, leading to misjudgments or incorrect conclusions. Therefore, data preprocessing can be performed in advance.
[0066] It should be noted that outliers are data points that deviate significantly from other observations in a dataset. These data points may be caused by measurement errors, data entry errors, missing values, or actual abnormalities. Missing values are data points that are missing from a dataset. They may be caused by data collection failures, data loss, etc.
[0067] Specifically, outliers and missing values can be identified through statistical methods (such as Z scores, IQR scores) or visualization methods (such as box plots). Depending on the specific situation, outliers and missing values can be deleted or replaced with reasonable values (such as medians or means).
[0068] Step S103: determining an average flow rate ratio at the current monitoring moment based on the first historical flow rate data, the second historical flow rate data and the current flow rate data at the current monitoring moment.
[0069] In this application, the short-term average flow rate at the current monitoring moment is calculated based on the first historical flow data and the current flow data at the current monitoring moment. The long-term average flow rate at the current monitoring moment is calculated based on the second historical flow data and the current flow data at the current monitoring moment. The average flow rate ratio at the current monitoring moment is calculated based on the short-term average flow rate at the current monitoring moment and the long-term average flow rate at the current monitoring moment.
[0070] Specifically, the first historical traffic data and the current traffic data at the current monitoring moment are added together to obtain the sum of all traffic data in the short-term window, and then all traffic data are divided by the number of data points in the short-term window to obtain the short-term average traffic at the current monitoring moment; the second historical traffic data and the current traffic data at the current monitoring moment are added together to obtain all traffic data in the long-term window, and then all traffic data are divided by the number of data points in the long-term window to obtain the long-term average traffic at the current monitoring moment; the STA at the current monitoring moment is divided by the LTA at the current monitoring moment to obtain the average traffic ratio at the current monitoring moment. For details, please refer to the following formula:
[0071]
[0072] Where STA(t) is the short-term average flow rate at the current monitoring time; LTA(t) is the long-term average flow rate at the current monitoring time; and Ratio(t) is the average flow rate ratio at the current monitoring time.
[0073] For ease of understanding, the following example is given: the current monitoring time is 14:00, and the preset short-term window is 5 minutes. The time period corresponding to the short-term window is the historical traffic data [100, 120, 110, 130] from 13:56 to 13:59 and the current traffic data
[150] at 14:00. The STA(t1) at the current monitoring time is (100+120+110+130+150) / 5=122. The preset long-term window is 60 minutes. The time period corresponding to the short-term window is the historical traffic data from 13:01 to 13:59 and the current traffic data
[150] at 14:00. The LTA(t1) at the current monitoring time is 305; Ratio(t1)=122 / 305=0.4.
[0074] The long-term average traffic at the current monitoring time reflects the traffic situation of the microservice interface over a longer period of time, providing a stable traffic baseline. By comparing the short-term average traffic at the current monitoring time with the long-term average traffic at the current monitoring time, you can assess the stability of the microservice interface traffic. If the average traffic ratio at the current monitoring time is close to 1, it indicates that the short-term traffic at the current monitoring time is close to the long-term traffic at the current monitoring time, and the traffic at the current monitoring time is relatively stable. If the average traffic ratio at the current monitoring time fluctuates significantly, it indicates that the traffic at the current monitoring time is unstable and there may be potential problems.
[0075] Furthermore, by analyzing historical data on average traffic ratios, we can identify cyclical changes and trends in traffic. For example, if the average traffic ratio increases significantly during a certain time period each day, this may indicate a peak business period, allowing for early preparation. Average traffic ratios can provide data support for business decisions. For example, based on changes in average traffic ratios, we can determine whether to increase service capacity, optimize interface performance, or adjust business policies.
[0076] After preprocessing the above data, the average flow ratio at the current monitoring moment may be determined based on the preprocessed first historical flow data, the preprocessed second historical flow data, and the preprocessed current flow data at the current monitoring moment.
[0077] Step S104: Based on the average traffic ratio at the current monitoring moment and the current traffic threshold, a traffic warning is issued to the microservice interface.
[0078] In this application, it is determined whether the average flow rate ratio at the current monitoring time is greater than the current flow threshold. If the average flow rate ratio at the current monitoring time is greater than the current flow threshold, a flow warning is issued to the microservice interface. For ease of understanding, please refer to Figure 3 , Figure 3 A broken line diagram of the average flow ratio and the current flow threshold is provided in an embodiment of the present application, wherein the horizontal axis of the broken line diagram represents each minute from June 1, 2024 to August 13, 2024, and the vertical axis of the broken line diagram represents the average flow ratio per minute and the value of the current flow threshold.
[0079] It should be noted that the current traffic threshold can be used to distinguish normal traffic from abnormal traffic, and can also be used to trigger an alarm operation. The initial value T0 of the current traffic threshold can be determined by analyzing the statistical characteristics of historical traffic data. Specifically, first obtain the third historical traffic data of the preset historical monitoring time period, and calculate the average value and standard deviation of the average traffic ratio of each historical monitoring moment in the preset historical monitoring time period based on the third historical traffic data. The preset historical monitoring time period is earlier than the time period corresponding to the preset short-term window and the time period corresponding to the preset long-term window; based on the average value and standard deviation of the average traffic ratio of each historical monitoring moment, the initial value of the current traffic threshold is calculated.
[0080] The preset historical monitoring period should be earlier than the preset short-term window and the preset long-term window, and should be long enough to cover normal traffic fluctuations while avoiding the impact of short-term abnormal traffic. For example, if the preset short-term window corresponds to 13:56-14:00 on June 20, 2024, and the preset long-term window corresponds to 13:01-14:00 on June 20, 2024, then the preset historical monitoring period can be 1:01-23:00 on June 19, 2024.
[0081] For each historical monitoring moment, we can first obtain the fourth historical flow data of the time period corresponding to the preset short-term window before the historical monitoring moment and the fifth historical flow data of the time period corresponding to the preset long-term window before the historical monitoring moment; then, based on the fourth historical flow data and the third historical flow data at the historical monitoring moment, calculate the short-term average flow at the historical monitoring moment; then, based on the fifth historical flow data and the third historical flow data at the historical monitoring moment, calculate the long-term average flow at the historical monitoring moment; finally, based on the short-term average flow at the historical monitoring moment and the long-term average flow at the historical monitoring moment, calculate the average flow ratio at the historical monitoring moment.
[0082] Specifically, the average value of the average flow ratio at each historical monitoring moment is obtained by dividing the sum of the average flow ratios at each historical monitoring moment by the total number of the average flow ratios at each historical monitoring moment. The average value of the average flow ratio represents the average level of the average flow ratio; the standard deviation of the average flow ratio at each historical monitoring moment is obtained by first calculating the square value of the difference between the average flow ratio at each historical monitoring moment and the average value of the average flow ratio at each historical monitoring moment, and then dividing the square value by the total number of the average flow ratios at each historical monitoring moment to obtain the average square difference and taking the square root. The standard deviation of the average flow ratio represents the average distance between each average flow ratio and the average value of the average flow ratio. Based on the average value and standard deviation of the third historical flow data, the initial value of the current flow threshold is calculated. For details, please refer to the following formula:
[0083] T0=μ+kσ
[0084] where μ is the mean of the average flow ratios, σ is the standard deviation of the average flow ratios, and k is a constant (such as 3 or 4).
[0085] By establishing reasonable current traffic thresholds and early warning mechanisms, sudden increases in traffic can be detected promptly and appropriate measures can be taken to ensure system stability and performance. Specifically, if the average traffic ratio at the current monitoring moment is greater than the current traffic threshold (e.g., Ratio(t1) > T0), this indicates a sudden increase in current traffic data. Traffic early warnings can be used to promptly detect and address this increase, preventing system overload or performance degradation.
[0086] Step S105: Based on the preset smoothing factor and the average flow rate ratio at the current monitoring moment, the current flow rate threshold is updated using the exponentially weighted moving average method.
[0087] In this application, based on a preset smoothing factor and the average flow rate ratio at the current monitoring moment, an exponentially weighted moving average method is used to dynamically update the current flow threshold. The core idea of this method is to give more weight to the most recent data points while retaining some of the influence of previous data, thereby more flexibly adapting to changes in flow. For details, please refer to the following formula:
[0088] T t+1 =(1-α)T t +αRatio(t)
[0089] Among them, T t is the flow threshold at the current monitoring moment; T t+1 is the flow threshold at the next monitoring moment of the current monitoring moment; α is the preset smoothing factor; Ratio(t) is the average flow ratio at the current monitoring moment.
[0090] It should be noted that the preset smoothing factor α is used to control the importance of new data points relative to old data points. When the value is close to 0, the old data points have a greater impact, the flow threshold changes more slowly, and the sensitivity to short-term fluctuations is less. When the smoothing factor α is close to 1, new data points have a greater impact on the results, and the flow threshold responds more quickly to the latest flow changes. The preset smoothing factor α is usually close to 0. (1-α)T t This part retains the current flow threshold T t , where (1−α) is usually close to 1, indicating that most of the current threshold is retained. αRatio(t) is the part that is adjusted based on the average flow ratio Ratio(t) at the current monitoring moment, and the smoothing factor α determines the magnitude of the adjustment.
[0091] For ease of understanding, an example is given below: the current flow threshold T0 at the current monitoring moment is 1.2, the average flow ratio Ratio(t0) at the current monitoring moment is 1.5, and the preset smoothing factor α is 0.2. Therefore, the current flow threshold at the current monitoring moment is updated to T1 = (1-0.2) × 1.2 + 0.2 × 1.5 = 1.26.
[0092] At this time, the current monitoring moment is updated to the next monitoring moment of the current monitoring moment. First, the current flow data of the current monitoring moment can be determined, and then the sixth historical flow data of the time period corresponding to the preset short-term window before the current monitoring moment and the seventh historical flow data of the time period corresponding to the preset long-term window before the current monitoring moment; then based on the sixth historical flow data and the current flow data, the short-term average flow at the current monitoring moment is calculated; then based on the seventh historical flow data and the current flow data, the long-term average flow at the current monitoring moment is calculated; finally, based on the short-term average flow at the current monitoring moment and the long-term average flow at the current monitoring moment, the average flow ratio Ratio(t1)=1.3 at the current monitoring moment is calculated.
[0093] If the average traffic ratio Ratio(t1)=1.3 at the current monitoring time is greater than the current traffic threshold T1=1.26 at the current monitoring time, a traffic warning is issued for the microservice interface. Finally, based on the preset smoothing factor α=0.2 and the average traffic ratio Ratio(t1)=1.3 at the current monitoring time, the exponentially weighted moving average method is used to update the current traffic threshold T1=1.26 at the current monitoring time to T2=(1-0.2)×1.26+0.2×1.3=1.268. For ease of understanding, please refer to Figure 4 , Figure 4 A flowchart of a method for updating a current flow threshold provided in an embodiment of the present application.
[0094] In summary, the present application provides a traffic early warning method for a microservice interface, the method comprising: determining the current traffic data of the microservice interface at the current monitoring moment. Obtaining first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, wherein the end time of the time period corresponding to the preset short-term window is consistent with the end time of the time period corresponding to the preset long-term window, and the length of the time period corresponding to the preset short-term window is less than the length of the time period corresponding to the preset long-term window. The multi-dimensional data collection method provides a basis for subsequent dynamic analysis. Based on the first historical traffic data, the second historical traffic data, and the current traffic data at the current monitoring moment, the average traffic ratio at the current monitoring moment is determined. The average traffic ratio can reflect the short-term fluctuations and long-term trends of the traffic. Based on the average traffic ratio at the current monitoring moment and the current traffic threshold, a traffic early warning is issued for the microservice interface. Based on the preset smoothing factor and the average traffic ratio at the current monitoring moment, the current traffic threshold is updated using the exponentially weighted moving average method, realizing automatic adjustment of the threshold according to the actual changes in the traffic, making it closer to the current traffic conditions, facilitating more accurate judgment of whether the traffic is abnormal, avoiding false alarms and missed alarms, and thus improving the reliability of the traffic early warning.
[0095] The above describes a traffic early warning method for a microservice interface provided by an embodiment of the present application. The following describes a traffic early warning device for executing the above-mentioned microservice interface.
[0096] See also Figure 5 , Figure 5 This is a structural diagram of a traffic warning device for a microservice interface provided in an embodiment of the present application. The traffic warning device for the microservice interface is applied to the server, which is connected to the client. Figure 5 As shown, the traffic warning device of the microservice interface includes:
[0097] The first determining unit 11 is configured to determine current traffic data of the microservice interface at a current monitoring moment.
[0098] The acquisition unit 12 is used to obtain the first historical traffic data of the time period corresponding to the preset short-term window before the current monitoring moment and the second historical traffic data of the time period corresponding to the preset long-term window before the current monitoring moment, the end time of the time period corresponding to the preset short-term window is consistent with the end time of the time period corresponding to the preset long-term window, and the length of the time period corresponding to the preset short-term window is less than the length of the time period corresponding to the preset long-term window.
[0099] The second determining unit 13 is configured to determine an average flow rate ratio at the current monitoring moment based on the first historical flow rate data, the second historical flow rate data, and the current flow rate data at the current monitoring moment.
[0100] The early warning unit 14 is configured to issue a traffic early warning to the microservice interface based on the average traffic ratio at the current monitoring moment and the current traffic threshold.
[0101] The updating unit 15 is configured to update the current flow threshold by using an exponentially weighted moving average method based on a preset smoothing factor and the average flow ratio at the current monitoring moment.
[0102] In a possible implementation, the second determining unit 13 includes:
[0103] The first calculation subunit is configured to calculate the short-term average flow at the current monitoring moment based on the first historical flow data and the current flow data at the current monitoring moment.
[0104] The second calculation subunit is used to calculate the long-term average flow at the current monitoring moment based on the second historical flow data and the current flow data at the current monitoring moment.
[0105] The third calculation subunit is configured to calculate the average flow rate ratio at the current monitoring moment based on the short-term average flow rate at the current monitoring moment and the long-term average flow rate at the current monitoring moment.
[0106] In a possible implementation, the apparatus further includes:
[0107] A data acquisition unit is used to obtain third historical traffic data of a preset historical monitoring time period, and calculate the average value and standard deviation of the average traffic ratio of each historical monitoring moment in the preset historical monitoring time period based on the third historical traffic data. The preset historical monitoring time period is earlier than the time period corresponding to the preset short-term window and the time period corresponding to the preset long-term window.
[0108] The initial value calculation unit calculates the initial value of the current flow threshold based on the average value and the standard deviation of the average flow ratio at each of the historical monitoring moments.
[0109] In a possible implementation, the early warning unit 14 includes:
[0110] The judging subunit is configured to judge whether the average flow rate ratio at the current monitoring moment is greater than the current flow threshold.
[0111] The early warning subunit is configured to issue a traffic early warning to the microservice interface if the average traffic ratio at the current monitoring moment is greater than the current traffic threshold.
[0112] In a possible implementation, the apparatus further includes:
[0113] A preprocessing unit is used to preprocess the first historical flow data, the second historical flow data and the current flow threshold at the current monitoring moment respectively to obtain the preprocessed first historical flow data, the preprocessed second historical flow data and the preprocessed current flow data at the current monitoring moment.
[0114] The second determining unit 13 includes:
[0115] The determination subunit is configured to determine the average flow ratio at the current monitoring moment based on the preprocessed first historical flow data, the preprocessed second historical flow data, and the preprocessed current flow data at the current monitoring moment.
[0116] An electronic device is also provided in an embodiment of the present application. Figure 6 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments of the present application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0117] like Figure 6 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 602 or programs loaded from a storage device 608 into a random access memory (RAM) 603. When the electronic device is powered on, the RAM 603 also stores various programs and data required for the operation of the electronic device. The processing device 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0118] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a memory card, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Figure 6The electronic device is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.
[0119] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements a traffic warning method for any microservice interface provided in the embodiment of the present application.
[0120] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement a traffic warning method for any microservice interface provided in an embodiment of the present application.
[0121] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.
[0122] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.
[0123] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0124] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website, a computer, a training device or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
Claims
1. A traffic warning method for a microservice interface, characterized in that: include: Determine the current traffic data of the microservice interface at the current monitoring moment; Obtaining first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, wherein the end time of the time period corresponding to the preset short-term window is consistent with the end time of the time period corresponding to the preset long-term window, and the length of the time period corresponding to the preset short-term window is less than the length of the time period corresponding to the preset long-term window; determining an average flow rate ratio at the current monitoring moment based on the first historical flow data, the second historical flow data, and the current flow data at the current monitoring moment; Based on the average traffic ratio and the current traffic threshold at the current monitoring time, a traffic warning is issued to the microservice interface; Based on a preset smoothing factor and the average flow rate ratio at the current monitoring moment, the current flow rate threshold is updated using an exponentially weighted moving average method.
2. The traffic early warning method for the microservice interface according to claim 1 is characterized in that: The determining the average flow ratio at the current monitoring moment based on the first historical flow data, the second historical flow data, and the current flow data at the current monitoring moment includes: Calculating the short-term average flow rate at the current monitoring moment based on the first historical flow rate data and the current flow rate data at the current monitoring moment; Calculating the long-term average flow rate at the current monitoring moment based on the second historical flow rate data and the current flow rate data at the current monitoring moment; The average flow rate ratio at the current monitoring moment is calculated based on the short-term average flow rate at the current monitoring moment and the long-term average flow rate at the current monitoring moment.
3. The traffic early warning method for the microservice interface according to claim 1 is characterized in that: The process of determining the initial value of the current flow threshold includes: Obtaining third historical traffic data for a preset historical monitoring time period, and calculating, based on the third historical traffic data, an average value and a standard deviation of average traffic ratios at each historical monitoring moment in the preset historical monitoring time period, wherein the preset historical monitoring time period is earlier than a time period corresponding to the preset short-term window and a time period corresponding to the preset long-term window; An initial value of the current flow threshold is calculated based on the average value and the standard deviation of the average flow ratio at each of the historical monitoring moments.
4. The traffic early warning method for the microservice interface according to claim 1 is characterized in that: The performing traffic warning on the microservice interface based on the average traffic ratio and the current traffic threshold at the current monitoring moment includes: Determining whether the average flow rate ratio at the current monitoring moment is greater than the current flow threshold; If the average flow rate at the current monitoring moment is greater than the current flow threshold, a flow warning is issued to the microservice interface.
5. The traffic early warning method of the microservice interface according to claim 1 is characterized in that: After obtaining first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, the method further includes: Preprocessing the first historical flow data, the second historical flow data, and the current flow threshold at the current monitoring moment respectively to obtain preprocessed first historical flow data, preprocessed second historical flow data, and preprocessed current flow data at the current monitoring moment; The determining the average flow ratio at the current monitoring moment based on the first historical flow data, the second historical flow data, and the current flow data at the current monitoring moment includes: Based on the preprocessed first historical flow data, the preprocessed second historical flow data and the preprocessed current flow data at the current monitoring moment, an average flow ratio at the current monitoring moment is determined.
6. A traffic warning device for a microservice interface, characterized in that: include: A first determining unit is used to determine the current traffic data of the microservice interface at the current monitoring moment; an acquisition unit, configured to acquire first historical traffic data for a time period corresponding to a preset short-term window before the current monitoring moment and second historical traffic data for a time period corresponding to a preset long-term window before the current monitoring moment, wherein an end time of the time period corresponding to the preset short-term window is consistent with an end time of the time period corresponding to the preset long-term window, and a length of the time period corresponding to the preset short-term window is less than a length of the time period corresponding to the preset long-term window; a second determining unit, configured to determine an average flow rate ratio at the current monitoring moment based on the first historical flow rate data, the second historical flow rate data, and the current flow rate data at the current monitoring moment; An early warning unit, configured to issue a traffic early warning to the microservice interface based on the average traffic ratio at the current monitoring moment and a current traffic threshold; An updating unit is configured to update the current flow threshold by using an exponentially weighted moving average method based on a preset smoothing factor and the average flow ratio at the current monitoring moment.
7. The traffic warning device for the microservice interface according to claim 6, characterized in that: The second determining unit includes: a first calculation subunit, configured to calculate a short-term average flow rate at the current monitoring moment based on the first historical flow rate data and the current flow rate data at the current monitoring moment; a second calculation subunit, configured to calculate the long-term average flow rate at the current monitoring moment based on the second historical flow rate data and the current flow rate data at the current monitoring moment; The third calculation subunit is configured to calculate the average flow rate ratio at the current monitoring moment based on the short-term average flow rate at the current monitoring moment and the long-term average flow rate at the current monitoring moment.
8. A computer program product, characterized in that The method comprises computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement the traffic early warning method for the microservice interface according to any one of claims 1 to 5.
9. An electronic device, characterized in that: comprising at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the traffic early warning method of the microservice interface as described in any one of claims 1 to 5.
10. A computer storage medium, characterized in that The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the traffic warning method for the microservice interface as described in any one of claims 1 to 5.