Micrometer annotation-based index monitoring method and system
By introducing custom annotations and Apache JEXL engine parsing into the Micrometer monitoring library, combined with the AutoTimer of the Spring Boot framework, fine-grained monitoring of HTTP requests is achieved, solving the problem that native Micrometer cannot monitor request headers and return results, and improving monitoring Accuracy and visualization of data.
Patent Information
- Application Number
- CN202411166349.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-11-29
AI Technical Summary
The native Micrometer monitoring library cannot provide fine-grained monitoring information at the HTTP request level, which limits the in-depth analysis and monitoring capabilities of business data.
Through the method based on Micrometer annotation, HTTP requests are intercepted, request headers, request parameters and return results are parsed using the Apache JEXL engine, and combined with the AutoTimer of the Spring Boot framework, data is integrated into the Micrometer monitoring system, fine-grained monitoring indicators are generated, and through Grafana tool draws trend charts.
It realizes fine-grained monitoring of HTTP request parameters, header information and return results, improves the accuracy and visualization of monitoring data, reduces the intrusion of business logic, and is suitable for complex business scenarios.
Smart Images

Figure CN119052123A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data monitoring technology, and in particular to an indicator monitoring method and system based on Micrometer annotation. Background Art
[0002] Micrometer is a monitoring library widely used in Spring Boot projects to collect and export metrics about the runtime behavior of applications. Although Micrometer provides basic monitoring functions for HTTP request metrics, such as the number of requests and response time, it cannot provide more fine-grained monitoring information in its native form, such as request parameters or return results. This limits the ability of developers to conduct in-depth analysis and monitoring of business data, prompting developers to seek to expand or improve existing tools to meet more complex monitoring needs. Summary of the invention
[0003] This application proposes a method and system for implementing a custom business data indicator monitoring plug-in based on micrometer, which overcomes the shortcomings of the native micrometer in the prior art that it can only monitor request indicators at the http interface level and cannot perform fine-grained data monitoring:
[0004] The present invention provides an indicator monitoring method based on Micrometer annotation, and the implementation method includes:
[0005] responding to monitoring requests;
[0006] According to the monitoring request, a target monitoring annotation is established on the API interface corresponding to the current business, and the user ID is obtained according to the target monitoring annotation and transmitted to the monitoring indicator library to determine the monitoring target and the target monitoring data corresponding to the monitoring target;
[0007] When the http request is completed or an exception occurs, the http request is intercepted and the target monitoring component based on Micrometer is triggered to collect the target monitoring data;
[0008] Parse the collected target monitoring data based on the Apache JEXL engine and classify the elements or data with the same label into the corresponding label set;
[0009] Based on the AutoTimer automatic timer in the Spring Boot framework, the collected tag set is constructed and published to the monitoring system. The target instance is registered through Micrometer, and the target monitoring data is integrated into the updated Micrometer monitoring system. The trend chart of the target monitoring indicator can be drawn according to the user ID to achieve fine-grained monitoring and analysis of interface data.
[0010] Preferably, the monitoring target is the user ID obtained by creating a target monitoring annotation on the http method, and the target monitoring data corresponding to the monitoring target includes the attribute identifiers of the request header, request input parameters and return results declared in the monitoring annotation for monitoring; the target monitoring annotation includes a custom annotation named FxHttpParamTimed, which is used to mark the HTTP method that needs to be monitored.
[0011] Preferably, when the http request is completed or an exception occurs, the http request is intercepted, and the target monitoring component based on Micrometer is triggered to perform the collection of target monitoring data, including:
[0012] Create a new target class to implement the OncePerRequestFilter interface in the Spring framework. The new target class acts as an annotation processor to intercept and process http requests with the FxHttpParamTimed annotation.
[0013] Override the doFilterInternal method in the updated target class and write custom request processing logic to capture target monitoring data;
[0014] When an http request annotated with FxHttpParamTimed is processed or an exception occurs, the capture logic of the target monitoring data is activated;
[0015] Retrieve an instance of the FxHttpParamTimed annotation from the HandlerMethod object of the current request.
[0016] Preferably, parsing the collected target monitoring data based on the Apache JEXL engine includes:
[0017] Get the defined headerTag attribute according to the target monitoring annotation, parse the headerTag, and get the target request header parameters;
[0018] Apache JEXL engine is used to parse and extract parameter values corresponding to target request header parameters from the request header, and the obtained target request header parameters are added to the corresponding tag set; and / or,
[0019] Obtain the defined paramTag attribute according to the target monitoring annotation, parse the paramTag, and obtain the target request input parameter;
[0020] Apache JEXL engine is used to parse and extract parameter values corresponding to target request input parameters from request input parameters, and the obtained target request input parameters are added to the corresponding tag set; and / or,
[0021] Get the defined responseTag attribute according to the target monitoring annotation, parse the responseTag, and get the target return result parameter;
[0022] The Apache JEXL engine is used to parse and extract the parameter values corresponding to the target return result parameters from the response, and the obtained target return result parameters are added to the corresponding tag set.
[0023] Preferably, drawing a trend graph of the target monitoring indicator according to the user ID includes:
[0024] Configure the target monitoring data as a data source based on the Granfana tool; create a new dashboard and set one or more charts to achieve visual monitoring of the target monitoring indicators; use the chart configuration interface as a query editor to write and process PromQL statement queries; to extract the target monitoring indicators related to the user ID;
[0025] The results of the PromQL statement query are displayed in a chart using visual configuration options; visual configuration options include color coding, legend configuration, and time range selection.
[0026] The present invention provides an indicator monitoring system based on Micrometer annotation, comprising:
[0027] An acquisition module, for responding to a monitoring request;
[0028] The configuration module is used to establish a target monitoring annotation on the API interface corresponding to the current business according to the monitoring request, obtain the user ID according to the target monitoring annotation and transmit it to the monitoring indicator library to determine the monitoring target and the target monitoring data corresponding to the monitoring target;
[0029] The interception module is used to intercept the http request when it is completed or an exception occurs, and trigger the target monitoring component based on Micrometer to perform the collection of target monitoring data;
[0030] The parsing module is used to parse the collected target monitoring data based on the Apache JEXL engine and classify the elements or data with the same label into the corresponding label set;
[0031] The integration module is used to build a collected tag set based on the AutoTimer automatic timer in the Spring Boot framework, and publish the tag set to the monitoring system. It registers the target instance through Micrometer and integrates the target monitoring data into the updated Micrometer monitoring system. It can draw a trend chart of the target monitoring indicator according to the user ID to achieve fine-grained monitoring and analysis of interface data.
[0032] Preferably, the monitoring target is the user ID obtained by creating a target monitoring annotation on the http method, and the target monitoring data corresponding to the monitoring target includes the attribute identifiers of the request header, request input parameters and return results declared in the monitoring annotation for monitoring; the target monitoring annotation includes a custom annotation named FxHttpParamTimed, which is used to mark the HTTP method that needs to be monitored.
[0033] Preferably, the parsing module includes:
[0034] The request header parsing unit is used to obtain the defined headerTag attribute according to the target monitoring annotation, parse the headerTag, and obtain the target request header parameter; the Apache JEXL engine is used to parse and obtain the parameter value corresponding to the target request header parameter extracted from the request header, and the obtained target request header parameter is added to the corresponding tag set;
[0035] The request input parameter parsing unit is used to obtain the paramTag attribute defined according to the target monitoring annotation, parse the paramTag, and obtain the target request input parameter; the Apache JEXL engine is used to parse and extract the parameter value corresponding to the target request input parameter from the request input parameter, and the obtained target request input parameter is added to the corresponding tag set;
[0036] The return result parsing unit is used to obtain the defined responseTag attribute according to the target monitoring annotation, parse the responseTag, and obtain the target return result parameter; the Apache JEXL engine is used to parse and obtain the parameter value corresponding to the target return result parameter extracted from the response, and the obtained target return result parameter is added to the corresponding tag set.
[0037] The present invention provides an electronic device, comprising:
[0038] A memory, the memory is used to store the processing program;
[0039] The processor implements the indicator monitoring method based on Micrometer annotation as described in the embodiment of the present invention when executing the processing program.
[0040] The present invention provides a readable storage medium, on which a processing program is stored. When the processing program is executed by a processor, an indicator monitoring method based on Micrometer annotation as described in an embodiment of the present invention is implemented.
[0041] Compared with the prior art, the present invention has at least one of the following beneficial effects:
[0042] (1) Improved fine-grained monitoring capabilities. By introducing custom annotations to monitor HTTP request parameters, header information, and return results, and storing the data in the form of tags in the monitoring indicator library, the problem of the original monitoring tool's inability to obtain fine-grained data on HTTP requests is solved. The granularity of monitoring data is improved, and performance issues of specific API calls can be more accurately identified and analyzed.
[0043] (2) The business logic is less invasive. The present invention implements the monitoring function by annotation, without changing the existing business code structure. Complex monitoring logic can be implemented by simply adding annotations to the monitoring method. This non-invasive design reduces interference with business logic and improves the ease of use and maintainability of the monitoring function.
[0044] (3) Flexible data acquisition: The Apache JEXL engine can dynamically extract monitoring data from HTTP requests, and the monitoring logic can be customized according to specific needs, making it suitable for various complex business scenarios.
[0045] (4) Improve the visualization and availability of monitoring data. The collected data is integrated into the monitoring system through Micrometer, which improves the availability of data. At the same time, the Grafana tool is used to achieve efficient visualization of data. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 This is a flowchart of the steps of the method for implementing a custom business data indicator monitoring plug-in based on micrometer of the present invention;
[0047] Figure 2 A simplified flow chart of a method for implementing a custom business data indicator monitoring plug-in based on micrometer in the present invention;
[0048] Figure 3 The present invention is a parameter parsing flow chart of the method for implementing a custom business data indicator monitoring plug-in based on micrometer. DETAILED DESCRIPTION
[0049] The inventive point of the present invention is to enrich the data information of the micrometer component when monitoring http requests. Since the native micrometer only has data information at the http interface level for monitoring http request indicators, there is no more fine-grained monitoring information, such as http request header information, request parameters in the interface, and information on returned results. This application is to support the monitoring module to collect fine-grained data such as request headers, input parameters, and results in request methods. In an annotated manner, the request parameters or return result data specified in the http request are collected, and then a personalized monitoring trend chart can be drawn in conjunction with grafana. Therefore, based on the collection of these fine-grained data, richer monitoring indicators can be obtained based on these diversified data, and at the same time, they are implemented in the form of annotations, which is simple to use and less invasive to business logic.
[0050] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0051] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0052] First embodiment
[0053] like Figures 1 to 3 As shown, this embodiment provides an indicator monitoring method based on Micrometer annotation, and the implementation method includes:
[0054] Step S1: responding to the monitoring request; it can be understood that it is triggered by the HTTP method, using the HTTP protocol to send a specific type of request (such as GET or POST) to start the relevant business process. For example, in a Web application, a user clicks a submit button to send form data, which is usually implemented through a POST request. After receiving this request, the server responds and executes the corresponding business logic according to the request content, such as processing form data, accessing a database, or performing other related operations.
[0055] Step S2: Establish a target monitoring annotation on the API interface corresponding to the current business according to the monitoring request, obtain the user ID according to the target monitoring annotation and transmit it to the monitoring indicator library to determine the monitoring target and the target monitoring data corresponding to the monitoring target, wherein the monitoring target is the user ID obtained by creating a target monitoring annotation on the http method, and the target monitoring data corresponding to the monitoring target includes the attribute identifiers of the request header, request input parameters and return results declared in the monitoring annotation for monitoring; the target monitoring annotation includes a custom annotation named FxHttpParamTimed, which is used to mark the HTTP method that needs to be monitored.
[0056] Specifically, the specific steps to establish monitoring annotations on the API interface corresponding to the current business include:
[0057] Create a monitoring annotation class and declare the attribute identifiers of the request header, request parameters, and return results used for monitoring in the monitoring annotation;
[0058] Then apply the monitoring annotation to the http method to be monitored to capture the specified monitoring data when the http method is called.
[0059] The specific steps for declaring a custom monitoring annotation on the http method that needs to be monitored are as follows:
[0060] ①Customize the monitoring annotation FxHttpParamTimed, and declare the attribute (parameter) identifiers of the request header, request parameters, and return results in FxHttpParamTimed;
[0061] ②Add custom monitoring annotations to the http method that needs to be monitored, and set the parameters that need to be monitored, for example: @FxMethodParamTimed(paramTag={"user.name"},responseTag={"user.age"},headerTag={"userId"}).
[0062] As shown in the code, @FxMethodParamTimed is a custom annotation used at the method level to monitor fine-grained business data; paramTag: This attribute is used to specify the data that needs to be monitored from the method input parameters. In this example, paramTag = {"user.name"} indicates that the monitoring system needs to capture and record the parameter value marked as user.name in the method input parameters; responseTag: This attribute is used to specify the data that needs to be monitored from the method return result. responseTag = {"user.age"} indicates that the monitoring system will track and record the information about user.age in the method return value; headerTag: This attribute is used to specify the data that needs to be monitored from the HTTP request header. headerTag = {"userId"} indicates that the monitoring system will capture and record information related to userId from the HTTP request header.
[0063] Step S3: When the http request is completed or an exception occurs, the http request is intercepted and the target monitoring component based on Micrometer is triggered to perform target monitoring data collection.
[0064] Specifically, when a business request is completed or abnormal, the http request is intercepted and the monitoring annotations defined on the API interface are extracted to mark specific data in the request so that these key information can be captured and recorded for more detailed performance analysis or fault diagnosis. This process is automated, ensuring that all data marked by annotations can be intercepted, identified and processed. Therefore, specifying monitoring parameters through annotations simplifies the monitoring configuration process and makes the business logic of the entire plug-in implementation system less invasive. Directly mark which methods or parameters need to be monitored in the code without modifying the core business logic or performing complex configurations, thereby reducing the complexity of the system and enhancing the maintainability of the code, making the deployment and maintenance of monitoring more direct and efficient. Therefore, the steps of step S3 specifically include,
[0065] Step S31: Create a new target class to implement the OncePerRequestFilter interface in the Spring framework. The new target class serves as an annotation processor to intercept and process http requests with the FxHttpParamTimed annotation.
[0066] Step S32: rewrite the doFilterInternal method in the updated target class and write a custom request processing logic to capture target monitoring data;
[0067] Step S33: When an http request with the FxHttpParamTimed annotation is processed or an exception occurs, the capture logic of the target monitoring data is activated to capture data at key moments in the request life cycle for subsequent analysis and monitoring;
[0068] Step S34: retrieve the instance of the FxHttpParamTimed annotation from the HandlerMethod object of the current request, that is, based on the detailed configuration of the monitoring annotation defined on the method, mark and collect the data that needs to be monitored.
[0069] Step S4: Parse the collected target monitoring data based on the Apache JEXL engine, and classify the elements or data with the same label into the corresponding label set.
[0070] Specifically, the field names of the required monitoring data are identified and parsed according to the monitoring annotations, and the corresponding parameter values are extracted from the business request and added to the label set; through the predefined monitoring annotations, the monitoring data fields specified in the business request are first identified and parsed. These fields include key information such as the request header, request parameters, and return results. This data is extracted from the business request and added to the label set as monitoring parameter values. This enables fine-grained monitoring of business requests, ensuring that key data is effectively captured and used for further analysis and generation of monitoring indicators. The transparency of data monitoring is improved, and the flexibility and accuracy of data processing are enhanced. Therefore, the steps of step S4 specifically include,
[0071] Step S41: Obtain the defined headerTag attribute according to the target monitoring annotation, parse the headerTag, and obtain the target request header parameter key (such as user.name);
[0072] The Apache JEXL engine is a library for executing scripts and expressions in Java applications. It allows developers to dynamically calculate, manipulate, or evaluate expressions at runtime; the flexibility of the engine is particularly suitable for situations where logic needs to be generated and executed based on dynamic conditions or configurations. At the same time, as a lightweight Java library, JEXL can be easily integrated into any Java application without complex dependencies or configurations. In this embodiment, the Apache JEXL engine allows parsing and calculation of dynamic data such as request headers, request parameters, and return results. This means that data extraction logic can be flexibly defined and adjusted based on the runtime data environment and context.
[0073] Apache JEXL engine is used to parse and extract parameter values corresponding to target request header parameters from the request header, and the obtained target request header parameters are added to the corresponding tag set; and / or,
[0074] Step S42: Obtain the paramTag attribute defined according to the target monitoring annotation, parse the paramTag, and obtain the target request input parameter key (such as user.age);
[0075] Apache JEXL engine is used to parse request.parameterMap to extract the parameter value corresponding to the target request input parameter from the request input parameter, and the obtained target request input parameter is added to the corresponding tag set; and / or, specifically, request.parameterMap is an attribute of the HttpServletRequest object in the JavaServletAPI, which provides a method to access all parameters in the HTTP request. ParameterMap is a mapping from string keys to string array values (Map<String,String[]> ), where each key is the name of a request parameter and the corresponding value is one or more values of that parameter. Here is a detailed explanation of this concept: Map<String,String[]> , which is a mapping table that stores request parameters, which allows obtaining the values of one or more parameters of the same name from the HTTP request. For example, if the HTTP request is a form submission, parameterMap will contain the names of all fields in the form and their corresponding values. The Apache JEXL engine uses request.parameterMap to parse the input parameters in the HTTP request. By querying and parsing this parameter map, specific data in the request can be dynamically obtained, such as form information submitted by the user. Then, these parameter values parsed from the request are added to the tag collection of the monitoring system for further data processing and analysis.
[0076] Step S43: Obtain the defined responseTag attribute according to the target monitoring annotation, parse the responseTag, and obtain the target return result parameter key (such as user.id);
[0077] The Apache JEXL engine is used to parse the response.OutputStream interface to extract the parameter value corresponding to the target return result parameter from the output stream in the response, and the obtained target return result parameter is added to the corresponding tag set. Specifically, response.OutputStream is an interface in the Java Servlet API for sending binary data to the client. Therefore, it is an output stream that allows the server to write data to the client, usually used to generate the content of the response. In this context, it is used to access and manipulate the data content of the HTTP response. The parameter value refers to the specific data point extracted from the HTTP request or response. These parameter values can be any data extracted from the request or response, such as user ID, status code, response time, etc.
[0078] Step S5: Based on the AutoTimer automatic timer in the Spring Boot framework, the collected tag set is constructed to form the monitoring indicators of Micrometer, and the tag set is published to the monitoring system. The target instance is registered through Micrometer to complete the storage process, and the target monitoring data is integrated into the updated Micrometer monitoring system. The trend chart of the target monitoring indicator can be drawn according to the user ID to achieve fine-grained monitoring and analysis of the interface data.
[0079] The specific steps of registering monitoring data are to obtain the AutoTimer of spring.actuate, build the collected tag set into the AutoTimer, then publish the data to the monitoring system, obtain the Timer.Builder of micrometer, and then register the Builder into the MeterRegistry. It can be understood that the MeterRegistry acts as a monitoring indicator library, responsible for storing and managing all monitoring data.
[0080] Specifically, the tag collection is stored in the Micrometer monitoring indicator library; the data can be integrated into a format that Micrometer can recognize and registered with the system's monitoring framework. In this way, the collected data is not only recorded by the system, but can also be used to generate real-time monitoring charts and analysis reports to support deeper data insights and decision support. The tag data stored in the Micrometer monitoring indicator library is filtered based on specific monitoring requirements, such as the activities of a specific user or the flow of data within a specific time period. The filtered data is used to draw trend charts through integrated drawing tools such as Grafana, making data monitoring more refined. Among them, the trend charts of the target monitoring indicators drawn according to the user ID include:
[0081] Step S51: Based on the Granfana tool, configure the target monitoring data as a data source; create a new dashboard, set one or more charts to achieve visual monitoring of the target monitoring indicators; use the chart configuration interface as a query editor to write and process PromQL statement queries; to extract the target monitoring indicators related to the user ID;
[0082] Grafana is an open source platform for visualizing and analyzing metric data. It supports multiple data sources, including but not limited to Prometheus, InfluxDB, and Elasticsearch, and is suitable for various monitoring and data analysis tools. Grafana enables users to create detailed visualization dashboards that display data in real time and support a variety of graphic options such as line graphs, bar graphs, and heat maps to meet complex data display needs.
[0083] Step S52: Display the result of the PromQL statement query in a chart through visual configuration options; the visual configuration options include color coding, legend configuration and time range selection.
[0084] In this embodiment, it can be understood that a monitoring indicator library connected to Micrometer is set in Grafana to access the source of monitoring data;
[0085] Construct a query statement to query data and select the corresponding chart type, map the query results to the coordinate axes of the chart; and customize the chart as needed, including color adjustment, line thickness, and adding labels.
[0086] The specific steps of the method for drawing indicators using monitoring data are as follows: after adding personalized data to the monitoring data, the request status can be monitored from multiple dimensions. For example, the following query statement for drawing a custom monitoring indicator based on userId is as follows:
[0087] sumwithout(instance,ip)(fx_http_server_requests_seconds_count{application=~"$application",GW_USER_ID=~"$userId"}), where "GW_USER_ID" is a custom monitoring parameter.
[0088] This query statement is used to count the HTTP request time of a specific user on all server instances. Here, sumwithout(instance,ip) means to sum all instances and IP addresses, but not to classify by these tags, but only by application and user ID.
[0089] fx_http_server_requests_seconds_count{application=~"$application",GW_USER_ID=~"$userId"} is a monitoring indicator, where application and GW_USER_ID are filter conditions for selecting specific applications and user IDs. Such queries are helpful for analyzing the request performance of different users on different applications.
[0090] The following two practical application examples demonstrate how this method can provide key data support and optimize decision-making and processes in different business environments. The first is the customer dimension request monitoring of the foreign exchange OpenApi, which shows how to perform fine-grained monitoring of the API usage of external customers. The second is the monitoring of the internal batch inquiry function, which illustrates how to achieve accurate data capture in internal business processes and fill the gaps in the existing monitoring system, thus highlighting the flexibility and effectiveness of this technology in practical applications.
[0091] The first application example is about the monitoring of foreign exchange OpenApi customer dimension requests.
[0092] Forex OpenApi provides external customers with the ability to access foreign exchange through API. The technical team hopes to monitor the request indicators of each customer. However, the native micrometer cannot obtain user information inside the interface. This method can be used to customize monitoring annotations on the API method to achieve this goal, that is, the code example:
[0093] @FxMethodParamTimed(paramTag={"currencyType"}, responseTag={"exchangeRate"}, headerTag={"userId"});
[0094] In the application scenario of foreign exchange OpenAPI, "currencyType" is an API request parameter that specifies the specific currency type that the customer wants to query, such as the conversion of US dollars (USD) to euros (EUR). "exchangeRate" is the return value in the API response, which represents the queried exchange rate. In this context, the technical team hopes to analyze and optimize the service by monitoring the request indicators of each customer. However, the native Micrometer cannot obtain user information inside the interface. This monitoring plug-in solves the problem of obtaining fine-grained monitoring data. By adding custom monitoring annotations to the API interface and indicating that userId is obtained from the parameters, fine-grained monitoring of each customer request can be achieved.
[0095] The second application example is about the monitoring of inquiry requests in the foreign exchange business line.
[0096] The foreign exchange department provides batch inquiry functions to other departments within the company. The technical team hopes to monitor the inquiry indicators of each business line. However, the native Micrometer cannot capture the specific business information inside the API. With this monitoring plug-in, you can add custom monitoring annotations to the API interface to accurately obtain and monitor the inquiry data of each business line.
[0097] That is, code example: @FxMethodParamTimed(paramTag={"currencyType"},responseTag={"exchangeRate"},headerTag={"userId"})
[0098] productType is an API request parameter, which is used to specify the product type to be queried, such as the category of foreign exchange products. price is the return value of the API response, which indicates the queried product quotation. agentId is a parameter obtained from the request header, which is used to identify the specific business line or operator of the request. Similarly, by directly adding monitoring annotations to the inquiry interface and indicating that agentId is obtained from the parameters, the inquiry indicators of each business line can be monitored.
[0099] Second embodiment
[0100] Based on the same inventive concept, the present invention provides an indicator monitoring system based on Micrometer annotation, including:
[0101] An acquisition module, for responding to a monitoring request;
[0102] Configuration module, used to establish target monitoring annotations on the API interface corresponding to the current business according to the monitoring request, obtain the user ID according to the target monitoring annotation and transmit it to the monitoring indicator library to determine the monitoring target and the target monitoring data corresponding to the monitoring target; wherein, the monitoring target is the user ID obtained by creating a target monitoring annotation on the http method, and the target monitoring data corresponding to the monitoring target includes the attribute identifiers of the request header, request input parameters and return results declared in the monitoring annotation for monitoring; the target monitoring annotation includes a custom annotation named FxHttpParamTimed, which is used to mark the HTTP method that needs to be monitored
[0103] The interception module is used to intercept the http request when it is completed or an exception occurs, and trigger the target monitoring component based on Micrometer to perform the collection of target monitoring data;
[0104] The parsing module is used to parse the collected target monitoring data based on the Apache JEXL engine and classify the elements or data with the same label into the corresponding label set; wherein the parsing module includes:
[0105] The request header parsing unit is used to obtain the defined headerTag attribute according to the target monitoring annotation, parse the headerTag, and obtain the target request header parameter; the Apache JEXL engine is used to parse and obtain the parameter value corresponding to the target request header parameter extracted from the request header, and the obtained target request header parameter is added to the corresponding tag set;
[0106] The request input parameter parsing unit is used to obtain the paramTag attribute defined according to the target monitoring annotation, parse the paramTag, and obtain the target request input parameter; the Apache JEXL engine is used to parse and extract the parameter value corresponding to the target request input parameter from the request input parameter, and the obtained target request input parameter is added to the corresponding tag set;
[0107] The return result parsing unit is used to obtain the defined responseTag attribute according to the target monitoring annotation, parse the responseTag, and obtain the target return result parameter; the Apache JEXL engine is used to parse and obtain the parameter value corresponding to the target return result parameter extracted from the response, and the obtained target return result parameter is added to the corresponding tag set.
[0108] The integration module is used to build a collected tag set based on the AutoTimer automatic timer in the Spring Boot framework, and publish the tag set to the monitoring system. It registers the target instance through Micrometer and integrates the target monitoring data into the updated Micrometer monitoring system. It can draw a trend chart of the target monitoring indicator according to the user ID to achieve fine-grained monitoring and analysis of interface data.
[0109] Third embodiment
[0110] In some embodiments of the present application, an electronic device is also provided. The electronic device includes a memory and a processor, wherein the memory is used to store a processing program; when the processor executes the processing program, the indicator monitoring method based on Micrometer annotation as described in the embodiment of the present invention is implemented. When the processor executes the processing program, the indicator monitoring method based on Micrometer annotation in the aforementioned embodiment is implemented.
[0111] Fourth embodiment
[0112] The present invention provides a readable storage medium, on which a processing program is stored, and when the processing program is executed by a processor, an indicator monitoring method based on Micrometer annotation as described in an embodiment of the present invention is implemented. A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. The computer-readable storage medium may be, for example, - but not limited to - an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the above. More specific examples (a non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a protruding structure in a groove on which instructions are stored, and any suitable combination of the above. The computer-readable storage medium used herein is not to be construed as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., light pulses through a fiber optic cable), or an electrical signal transmitted through wires.
[0113] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method of indicator monitoring based on Micrometer annotations, It is characterized in that The implementation method includes: responding to monitoring requests; According to the monitoring request, a target monitoring annotation is established on the API interface corresponding to the current business, and a user ID is obtained according to the target monitoring annotation and transmitted to the monitoring indicator library to determine the monitoring target and the target monitoring data corresponding to the monitoring target; When the http request is completed or an exception occurs, the http request is intercepted and the target monitoring component based on Micrometer is triggered to perform the collection of target monitoring data; Parsing the collected target monitoring data based on the Apache JEXL engine, and classifying elements or data with the same label into corresponding label sets; Based on the AutoTimer automatic timer in the Spring Boot framework, the collected tag set is constructed and published to the monitoring system. The target instance is registered through Micrometer, and the target monitoring data is integrated into the monitoring system of the updated Micrometer. The trend chart of the target monitoring indicator can be drawn according to the user ID to achieve fine-grained monitoring and analysis of interface data.
2. The indicator monitoring method based on Micrometer annotation as claimed in claim 1, It is characterized in that The monitoring target is the user ID obtained by creating the target monitoring annotation on the http method. The target monitoring data corresponding to the monitoring target includes the attribute identifiers of the request header, request input parameters and return results declared in the monitoring annotation for monitoring; the target monitoring annotation includes a custom annotation named FxHttpParamTimed, which is used to mark the HTTP method that needs to be monitored.
3. The indicator monitoring method based on Micrometer annotation as claimed in claim 1, It is characterized in that When the http request is completed or an exception occurs, the http request is intercepted and the target monitoring component based on Micrometer is triggered to perform the collection of target monitoring data, including: Create a new target class to implement the OncePerRequestFilter interface in the Spring framework, and the new target class acts as an annotation processor to intercept and process the http request with the FxHttpParamTimed annotation; Override the doFilterInternal method in the updated target class and write custom request processing logic to capture target monitoring data; When the http request with the FxHttpParamTimed annotation is processed or an exception occurs, the capture logic of the target monitoring data is activated; Retrieve the instance of the FxHttpParamTimed annotation from the HandlerMethod object of the current request.
4. The indicator monitoring method based on Micrometer annotation as claimed in claim 1, It is characterized in that Parsing the collected target monitoring data based on the Apache JEXL engine includes: Obtain the defined headerTag attribute according to the target monitoring annotation, parse the headerTag, and obtain the target request header parameter; The Apache JEXL engine is used to parse and extract parameter values corresponding to the target request header parameters from the request header, and the obtained target request header parameters are added to the corresponding tag set; and / or, Obtain the paramTag attribute defined according to the target monitoring annotation, parse the paramTag, and obtain the target request input parameter; The Apache JEXL engine is used to parse and extract the parameter value corresponding to the target request input parameter from the request input parameter, and the obtained target request input parameter is added to the corresponding tag set; and / or, Obtain the defined responseTag attribute according to the target monitoring annotation, parse the responseTag, and obtain the target return result parameter; The Apache JEXL engine is used to parse and extract parameter values corresponding to target return result parameters from the response, and the acquired target return result parameters are added to the corresponding tag set.
5. The indicator monitoring method based on Micrometer annotation as claimed in claim 1, It is characterized in that The trend graphs of target monitoring indicators drawn based on user ID include: Based on the Granfana tool, the target monitoring data is configured as a data source; a new dashboard is created, and one or more charts are set to realize visual monitoring of the target monitoring indicators; the configuration interface of the chart is used as a query editor to write and process PromQL statement queries; so as to extract the target monitoring indicators related to the user ID; The result of the PromQL statement query is displayed in a chart through visual configuration options; the visual configuration options include color coding, legend configuration and time range selection.
6. A Micrometer annotation-based indicator monitoring system, It is characterized in that include: An acquisition module, for responding to a monitoring request; A configuration module is used to establish a target monitoring annotation on the API interface corresponding to the current business according to the monitoring request, obtain a user ID according to the target monitoring annotation and transmit it to the monitoring indicator library to determine the monitoring target and the target monitoring data corresponding to the monitoring target; The interception module is used to intercept the http request when it is completed or an exception occurs, and trigger the target monitoring component based on Micrometer to perform the collection of target monitoring data; A parsing module, used to parse the collected target monitoring data based on the Apache JEXL engine, and classify elements or data with the same label into corresponding label sets; The integration module is used to build a collected tag set based on the AutoTimer automatic timer in the Spring Boot framework, and publish the tag set to the monitoring system. It registers the target instance through Micrometer, integrates the target monitoring data into the monitoring system of the updated Micrometer, and can draw a trend chart of the target monitoring indicator according to the user ID to achieve fine-grained monitoring and analysis of interface data.
7. According to the Micrometer annotation-based indicator monitoring system of claim 6, It is characterized in that The monitoring target is the user ID obtained by creating the target monitoring annotation on the http method. The target monitoring data corresponding to the monitoring target includes the attribute identifiers of the request header, request input parameters and return results declared in the monitoring annotation for monitoring; the target monitoring annotation includes a custom annotation named FxHttpParamTimed, which is used to mark the HTTP method that needs to be monitored.
8. According to the Micrometer annotation-based indicator monitoring system of claim 6, It is characterized in that The parsing module comprises: A request header parsing unit, used to obtain the defined headerTag attribute according to the target monitoring annotation, parse the headerTag, and obtain the target request header parameter; use the Apache JEXL engine to parse and extract the parameter value corresponding to the target request header parameter from the request header, and add the obtained target request header parameter to the corresponding tag set; A request input parameter parsing unit is used to obtain the paramTag attribute defined according to the target monitoring annotation, parse the paramTag, and obtain the target request input parameter; use the Apache JEXL engine to parse and extract the parameter value corresponding to the target request input parameter from the request input parameter, and add the obtained target request input parameter to the corresponding tag set; The return result parsing unit is used to obtain the defined responseTag attribute according to the target monitoring annotation, parse the responseTag, and obtain the target return result parameter; use the Apache JEXL engine to parse and obtain the parameter value corresponding to the target return result parameter extracted from the response, and add the obtained target return result parameter to the corresponding tag set.
9. An electronic device, It is characterized in that include: A memory, the memory being used to store a processing program; A processor, wherein when executing the processing program, the processor implements the indicator monitoring method based on Micrometer annotation as described in any one of claims 1 to 7.
10. A readable storage medium, It is characterized in that The readable storage medium stores a processing program, and when the processing program is executed by the processor, the indicator monitoring method based on Micrometer annotation as described in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Performance monitoring method and device, storage medium and electronic equipment
CN116389298A
API calling monitoring method and device, computer equipment and storage medium
CN121387674A
