A method for dynamically obtaining Nginx streaming media status information
By using custom modules and the HTTP-TS protocol to parse communication data, the problem of obtaining Nginx streaming media status information was solved, enabling real-time and flexible status monitoring and information updates.
Patent Information
- Application Number
- CN202411024237.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2044-07-29
AI Technical Summary
Existing technologies make it difficult to obtain Nginx streaming media status information, resulting in poor real-time performance, inflexible configuration, and insufficient real-time information.
Custom modules are introduced, including the status information access module ngx_http_live_stat_module and the processing module ngx_http_live_stat_handler. These modules parse communication data via the HTTP-TS protocol, record it in real time to the status page, configure a URI mapping monitoring module, and process the data using real-time data analysis algorithms.
It enables flexible configuration and real-time acquisition of Nginx streaming media status information, improving the timeliness and adaptability of information and ensuring the information is up-to-date.
Smart Images

Figure CN118827833B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer network technology, and in particular to a method for dynamically acquiring Nginx streaming media status information. Background Technology
[0002] In today's internet environment, Nginx, as a high-performance web server and reverse proxy server, is widely used in streaming media services. Nginx servers are renowned for their stability, rich feature set, sample configuration files, and low system resource consumption. In addition, Nginx servers possess the following characteristics: low memory consumption and high concurrency capabilities; Nginx server concurrency capabilities do indeed perform well among similar web servers. How to dynamically and in real-time monitor Nginx servers and how to determine their operational status in real-time have become pressing issues for the industry.
[0003] However, obtaining real-time streaming media status information is relatively difficult in traditional Nginx configuration and monitoring methods. Existing technologies mainly rely on log analysis or third-party monitoring tools, which suffer from high latency, insufficient real-time information, and lack of flexible configuration. Summary of the Invention
[0004] The purpose of this invention is to address the shortcomings of the existing technology by providing a method for dynamically acquiring Nginx streaming media status information. This method involves introducing a custom module that dynamically acquires key indicators and records this information in real-time to the status page, thereby achieving the goal of dynamically acquiring Nginx streaming media status information. The method includes:
[0005] A custom monitoring module implementing the HTTP-TS protocol is provided. This monitoring module parses the protocol communication data in real time and extracts key indicators, which are then dynamically recorded to the status page.
[0006] Configure the status page by setting a URI in the Nginx configuration file that maps to the status information recorded by the monitoring module;
[0007] Using real-time data analysis algorithms, the intercepted protocol data is processed in real time and transformed into the aforementioned status information.
[0008] Furthermore, the custom monitoring module is designed first, which includes a status information access module ngx_http_live_stat_module and a status information processing module ngx_http_live_stat_handler;
[0009] The status information access module ngx_http_live_stat_module allows users to view Nginx server status information via a specific URI.
[0010] The status information processing module ngx_http_live_stat_handler is executed during the nginix rewrite phase and does not respond to user requests. ngx_http_live_stat_handler is an Nginx module used to monitor the status of HTTP requests in real time.
[0011] Specifically, configuring the status information access module ngx_http_live_stat_module includes:
[0012] In the configuration file location, use the configuration directive http_live_staton|off to configure the on / off function of the monitoring module;
[0013] The configuration instructions are parsed using ngx_command_t and its related functions, functional functions are defined using ngx_http_module_t, configuration data is created and initialized, and modules are defined using ngx_module_t.
[0014] Write a config script and integrate it into the Nginx configuration file using the --add-module static linking option.
[0015] Preferably, the configuration instructions are parsed by defining configuration data structures and management functions, specifically including:
[0016] Define an enable variable of type ngx_flag_t in the data structure to convert the on / off information in the Nginx configuration file into 1 / 0 and save it.
[0017] Furthermore, the `gx_http_live_stat_handler` is used to parse protocol communication data in real time and extract key indicators to dynamically record them on the status page. Specifically, this includes:
[0018] S11: Obtain the connection object, read data using recv, create a request object, and begin parsing the request line;
[0019] S12: Collect the URIs, the number of clients corresponding to the URIs, IP addresses, and bandwidth usage through the ngx_http_request_t structure of each request, and store the data in the status page in a structured manner.
[0020] Before reading data using recv, it first checks whether the read event has timed out. If it has timed out, the request is terminated directly.
[0021] If an error occurs while reading data using recv, the request will be terminated immediately.
[0022] If recv cannot read data, add it to epoll monitoring and wait for the next read event.
[0023] Furthermore, when integrating the monitoring module, the configuration functions are first integrated, including:
[0024] The create function is called when parsing the configuration file location to create the configuration structure and then store it in the memory domain of the configuration file location.
[0025] The Init function is called after all configuration directives have been parsed, modifies the stage array of ngx_http_core_module, and registers the processing function.
[0026] After integrating the configuration function, the configuration instructions are integrated.
[0027] Furthermore, the key metrics include the number of requests, response time, error rate, bandwidth usage, and streaming media-specific metrics, which are calculated by parsing the HTTP-TS protocol communication data.
[0028] Compared with the prior art, the beneficial effects of the present invention are:
[0029] (1) This invention is developed through an HTTP-TS protocol monitoring module, which can flexibly configure the indicators to be monitored according to specific needs, making the system more adaptable to different application scenarios;
[0030] (2) This invention obtains the status information of the Nginx streaming media server in real time, including the number of connections, bandwidth usage, etc., by setting a URI mapping to the protocol monitoring module in the Nginx configuration file;
[0031] (3) The present invention uses an efficient real-time data analysis algorithm to dynamically update the status information periodically, ensuring that the information obtained by the user is up-to-date and improving the real-time nature of the information. Attached Figure Description
[0032] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0033] In the attached diagram:
[0034] Figure 1This is a flowchart of a method for dynamically obtaining Nginx streaming media status information according to the present invention;
[0035] Figure 2 This is a flowchart of the request processing process of the ngx_http_live_stat_handler, a status information processing module of the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0037] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of the stated 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.
[0038] The purpose of this invention is to provide a flexible and real-time method for monitoring the status information of an Nginx streaming media server. By introducing a custom module, this module can dynamically acquire key indicators and record this information to the status page in real time, thereby achieving the goal of dynamically acquiring Nginx streaming media status information.
[0039] The specific embodiments of the present invention will be described below with reference to the accompanying drawings and examples.
[0040] Example 1
[0041] like Figure 1 As shown in the figure, this embodiment provides a method for dynamically obtaining Nginx streaming media status information, the technical solution of which includes:
[0042] S1: A custom monitoring module that implements the HTTP-TS protocol. The monitoring module parses the protocol communication data in real time and extracts key indicators to dynamically record them to the status page.
[0043] S2: Configure the status page by setting a URI in the Nginx configuration file to map to the status information recorded by the monitoring module;
[0044] S3: Using real-time data analysis algorithms, the intercepted protocol data is processed in real time and converted into the aforementioned status information.
[0045] In step S1, the custom monitoring module is designed first. The monitoring module includes a status information access module ngx_http_live_stat_module and a status information processing module ngx_http_live_stat_handler.
[0046] The status information access module ngx_http_live_stat_module allows users to view Nginx server status information via a specific URI.
[0047] The status information processing module ngx_http_live_stat_handler is executed during the nginix rewrite phase and does not respond to user requests. ngx_http_live_stat_handler is an Nginx module used to monitor the status of HTTP requests in real time.
[0048] Specifically, configuring the status information access module ngx_http_live_stat_module includes:
[0049] In the configuration file location, use the configuration directive http_live_stat on|off to configure the on / off function of the monitoring module;
[0050] The configuration instructions are parsed using ngx_command_t and its related functions, functional functions are defined using ngx_http_module_t, configuration data is created and initialized, and modules are defined using ngx_module_t.
[0051] Write a config script and integrate it into the Nginx configuration file using the --add-module static linking option.
[0052] In this embodiment, the ngx_http_live_stat_module is represented in the Nginx configuration file as follows:
[0053] location / http_live_stat{
[0054] http_live_staton;
[0055] }
[0056] Parsing this configuration directive requires defining configuration data structures and management functions.
[0057] The configuration instructions are parsed by defining configuration data structures and management functions, specifically including:
[0058] Define an enable variable of type ngx_flag_t in the data structure to convert the on / off information in the Nginx configuration file into 1 / 0 and save it.
[0059] Specifically, in this embodiment, the configured data structure is as follows:
[0060] typedef struct{
[0061] ngx_flag_tenable;
[0062] }ngx_http_live_stat_loc_conf_t;
[0063] The configuration is parsed as follows:
[0064]
[0065] Furthermore, upon each incoming request, the gx_http_live_stat_handler parses the protocol communication data in real time, extracts key indicators, and dynamically records them to the status page, such as... Figure 2 As shown, it specifically includes:
[0066] S11: Obtain the connection object, read data using recv, create a request object, and begin parsing the request line;
[0067] S12: Collect the URIs, the number of clients corresponding to the URIs, IP addresses, and bandwidth usage through the ngx_http_request_t structure of each request, and store the data in the status page in a structured manner.
[0068] Specifically, before reading data using recv, check if the read event has timed out. If it has, terminate the request directly.
[0069] If an error occurs while reading data using recv, the request will be terminated immediately.
[0070] If recv cannot read data, add it to epoll monitoring and wait for the next read event.
[0071] Furthermore, when integrating the monitoring module, the configuration functions are first integrated, including:
[0072] The create function is called when parsing the configuration file location to create the configuration structure and then store it in the memory domain of the configuration file location.
[0073] The Init function is called after all configuration directives have been parsed, modifies the stage array of ngx_http_core_module, and registers the processing function.
[0074] After integrating the configuration function, the configuration instructions are integrated.
[0075] In this embodiment, the inherited configuration function is as follows:
[0076]
[0077] The inherited configuration directive is as follows:
[0078]
[0079] In step S1, the key metrics include the number of requests, response time, error rate, bandwidth usage, and streaming media-specific metrics, which are calculated by parsing the HTTP-TS protocol communication data.
[0080] In this embodiment, the monitoring module is named ngx_addon_name_ngx_live_stat_module, and its type is ngx_module_type = HTTP. The module's name in the code is ngx_module_name = ngx_http_live_stat_module, and the module's source code is ngx_module_srcs = "$ngx_addon_dir / ngx_http_live_module.c".
[0081] This invention introduces an HTTP-TS protocol monitoring module, which parses protocol communication data in real time and dynamically records it to the status page. The HTTP-TS protocol monitoring module achieves fast and accurate extraction of status information through efficient real-time data analysis.
[0082] Users can obtain real-time status information of the Nginx streaming media server, including the number of connections and bandwidth usage; the custom module allows users to flexibly configure the metrics to be monitored according to specific needs, making the system more adaptable to different application scenarios; the status information is dynamically updated periodically to ensure that the information obtained by users is up-to-date and improves the timeliness of information.
[0083] Obviously, those skilled in the art can make various modifications and variations to the invention without departing from the spirit and scope of the invention. Therefore, if these modifications and variations fall within the scope of the claims of the invention and their equivalents, the invention is also intended to include these modifications and variations.
[0084] Finally, it should be noted that the above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for dynamically obtaining Nginx streaming media status information, characterized in that, include: S1: A custom monitoring module implementing the HTTP-TS protocol, which parses protocol communication data in real time and extracts key indicators to dynamically record them on the status page; S2: Configure the status page by setting a URI in the Nginx configuration file to map to the status information recorded by the monitoring module; S3: Use real-time data analysis algorithms to process the intercepted protocol data in real time and convert it into the aforementioned status information; In step S1, the monitoring module includes a status information access module ngx_http_live_stat_module and a status information processing module ngx_http_live_stat_handler; The Nginx server status information can be accessed through the status information access module ngx_http_live_stat_module, allowing users to view this status information via the URI; The status information processing module ngx_http_live_stat_handler is executed during the nginix rewrite phase and does not respond to user requests. ngx_http_live_stat_handler is an Nginx module used to monitor the status of HTTP requests in real time.
2. The method for dynamically acquiring Nginx streaming media status information according to claim 1, characterized in that, Configuring the status information access module ngx_http_live_stat_module specifically includes: In the configuration file location, use the configuration directive http_live_stat on|off to configure the on / off function of the monitoring module; The configuration instructions are parsed using ngx_command_t and its related functions, functional functions are defined using ngx_http_module_t, configuration data is created and initialized, and modules are defined using ngx_module_t. Write a config script and integrate it into the Nginx configuration file using the --add-module static linking option.
3. The method for dynamically acquiring Nginx streaming media status information according to claim 2, characterized in that, The configuration instructions are parsed by defining configuration data structures and management functions, specifically including: Define an enable variable of type ngx_flag_t in the data structure, and convert the enable / disable information in the Nginx configuration file into 1 / 0 and save it.
4. The method for dynamically acquiring Nginx streaming media status information according to claim 1, characterized in that, Upon each incoming request, the ngx_http_live_stat_handler parses the protocol communication data in real time, extracts key metrics, and dynamically records them to the status page. Specifically, this includes: S11: Obtain the connection object, read data using recv, create a request object, and begin parsing the request line; S12: Collect the URIs, the number of clients corresponding to the URIs, IP addresses, and bandwidth usage through the ngx_http_request_t structure of each request, and store the data in the status page in a structured manner.
5. The method for dynamically acquiring Nginx streaming media status information according to claim 4, characterized in that, Before reading data using recv, check if the read event has timed out. If it has, terminate the request directly. If an error occurs while reading data using recv, the request will be terminated immediately. If recv cannot read data, add it to epoll monitoring and wait for the next read event.
6. The method for dynamically acquiring Nginx streaming media status information according to claim 2, characterized in that, When integrating the monitoring module, the configuration functions are first integrated, including: The create function is called when parsing the configuration file location to create the configuration structure and then store it in the memory domain of the configuration file location. The Init function is called after all configuration directives have been parsed, modifies the stage array of ngx_http_core_module, and registers the processing function. After integrating the configuration function, the configuration instructions are integrated.
7. The method for dynamically acquiring Nginx streaming media status information according to claim 1, characterized in that, In step S1, the key metrics include the number of requests, response time, error rate, bandwidth usage, and streaming media-specific metrics, which are calculated by parsing the protocol communication data.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method for dynamically obtaining Nginx streaming media status information as described in any one of claims 1-7.
9. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the method for dynamically acquiring Nginx streaming media status information as described in any one of claims 1-7.