WO2020199469A1 - 基于django框架的接口调用记录方法、装置、设备及存储介质 - Google Patents

基于django框架的接口调用记录方法、装置、设备及存储介质 Download PDF

Info

Publication number
WO2020199469A1
WO2020199469A1 PCT/CN2019/102218 CN2019102218W WO2020199469A1 WO 2020199469 A1 WO2020199469 A1 WO 2020199469A1 CN 2019102218 W CN2019102218 W CN 2019102218W WO 2020199469 A1 WO2020199469 A1 WO 2020199469A1
Authority
WO
WIPO (PCT)
Prior art keywords
interface call
signal
data
request
call request
Prior art date
Application number
PCT/CN2019/102218
Other languages
English (en)
French (fr)
Inventor
关琦
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020199469A1 publication Critical patent/WO2020199469A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the field of big data technology, and in particular to an interface call recording method, device, equipment and computer-readable storage medium based on the Django framework.
  • front-end user operation behaviors In order to better understand and analyze user behaviors and improve user experience, application operators need to obtain front-end user operation behaviors at the back end, and front-end user operation behaviors can be specifically requested through the front end to the back end.
  • the analysis shows that the back-end needs to record the front-end interface call request information.
  • the inventor realized that usually the front-end records the request information of the interface call and generates the log, and then uploads the log to the back-end. Therefore, the back-end cannot directly obtain the request information of the front-end interface call. It is not convenient to record the request information of the interface call.
  • the main purpose of this application is to provide a method, device, device, and computer-readable storage medium for recording interface calls based on the Django framework, aiming to solve the technical problem that the request information for recording interface calls in the prior art is not convenient enough.
  • this application provides an interface call recording method based on the Django framework, characterized in that the interface call recording method based on the Django framework includes the following steps:
  • the request information recorded by the thread shared variable is acquired and saved in a preset database.
  • the method before the step of detecting whether there is a start signal of the interface call request initiated by the front end, the method further includes:
  • triggering the custom middleware to create a custom thread shared variable to record the request information carried in the interface call request includes:
  • start signal of the interface call request currently exists, trigger the custom middleware to create a custom thread shared variable, and trigger the execution of the signal processing function bound to the start signal;
  • obtaining the request information recorded by the thread shared variable and saving it in a preset database includes:
  • the request information is used as user activity information and stored in the database according to a preset field format.
  • the request information includes: caller name, caller IP address, calling interface name, request time, and request content.
  • the method further includes:
  • the method further includes:
  • the data display plug-in corresponding to the data display mode is called to package the read processing data, and the report data is obtained and output and displayed.
  • this application also provides an interface call recording device based on the Django framework, and the interface call recording device based on the Django framework includes:
  • the detection module is used to detect whether there is a start signal of an interface call request initiated by the front end; and whether there is an end signal or an abnormal signal of the interface call request;
  • the recording module is used to trigger the custom middleware to create a custom thread shared variable if the start signal of the interface call request currently exists to record the request information carried in the interface call request;
  • the saving module is configured to obtain the request information recorded by the thread shared variable and save it in a preset database if the end signal or abnormal signal of the interface call request currently exists.
  • the present application also provides an interface call recording device based on the Django framework.
  • the interface call recording device based on the Django framework includes a memory, a processor, and stored on the memory and can be stored in the
  • the interface call recording program running on the processor implements the steps of the interface call recording method based on the Django framework as described in any of the above when the interface call recording program is executed by the processor.
  • the present application also provides a non-volatile computer-readable storage medium, the computer-readable storage medium stores an interface call recording program, and the interface call recording program is executed by the processor. The steps of calling the recording method based on the interface of the Django framework as described in any one of the above are implemented.
  • the back-end uses the signal mechanism of the django framework to monitor the interface call request initiated by the front-end, and obtain the request information in the front-end interface call, so that the back-end can directly obtain the request information of the front-end interface call.
  • the back-end uses the Django framework, even if the front-end uses other technical frameworks, it will not affect the back-end to record the request information of the interface call, which solves the problem that the back-end cannot directly obtain the request information of the front-end interface call in the front-end separation framework.
  • the present application further reduces the system overhead when the back-end obtains interface call request information.
  • FIG. 1 is a schematic structural diagram of an operating environment of a django framework-based interface call recording device involved in an embodiment of the application;
  • FIG. 2 is a schematic flowchart of the first embodiment of the interface call recording method based on the django framework of this application;
  • FIG. 3 is a schematic flowchart of a second embodiment of the interface call recording method based on the django framework of this application;
  • FIG. 4 is a schematic flowchart of a third embodiment of an interface call recording method based on the Django framework of this application;
  • FIG. 5 is a schematic flowchart of a fourth embodiment of an interface call recording method based on the django framework of this application;
  • Fig. 6 is a schematic diagram of functional modules of an embodiment of an interface call recording device based on the Django framework of this application.
  • This application provides an interface call recording device based on the django framework.
  • FIG. 1 is a schematic structural diagram of an operating environment of an interface call recording device based on a Django framework involved in a solution of an embodiment of the application.
  • the interface call recording device based on the Django framework includes a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005.
  • the communication bus 1002 is used to implement connection and communication between these components.
  • the user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard), and the network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory.
  • the memory 1005 may also be a storage device independent of the foregoing processor 1001.
  • the hardware structure of the interface call recording device based on the django framework shown in Figure 1 does not constitute a limitation on the interface call recording device based on the django framework, and may include more or less Components, or combination of certain components, or different component arrangements.
  • the memory 1005 which is a computer-readable storage medium, may include an operating system, a network communication module, a user interface module, and an interface call recording program.
  • the operating system is a program that manages and controls the interface call recording equipment and software resources based on the django framework, and supports the operation of the interface call recording program and other software and/or programs.
  • the network interface 1004 is mainly used to access the network; the user interface 1003 is mainly used to detect confirmation commands and edit commands, and the processor 1001 can be used
  • the interface call recording program stored in the call memory 1005 is called, and the following operations of each embodiment of the interface call recording method based on the django framework are performed.
  • Django framework is a framework based on MVC construction, which contains a "signal distributor", used to decouple various processing actions when the framework performs operations.
  • the django framework takes action, it will send out a signal, and the function that listens to this signal will be executed automatically.
  • the associated application can then be notified.
  • Django built-in signals include: built-in signals, database migration signals, request and response signals, test signals, etc.
  • built-in signals you need to register the corresponding function in the signal when you use it. When the application executes the corresponding operation, the registration function is automatically triggered.
  • django also allows custom signals. For the signal in django, you only need to register the function you want to execute in the signal, then when the action occurs, the registration function of the corresponding signal will be automatically executed.
  • the middleware in the django framework is actually a class in django, which contains multiple member functions.
  • django will execute the middleware at the right time according to its own rules Corresponding function.
  • FIG. 2 is a schematic flowchart of the first embodiment of the interface call recording method based on the Django framework of this application.
  • the interface call recording method based on the django framework includes the following steps:
  • Step S110 detecting whether there is a start signal of the interface call request initiated by the front end
  • a back-end system based on the django framework is constructed in advance, and the back-end uses the django framework to detect in real time an interface call request for a back-end interface initiated by a front-end or a third-party application, such as an Http request.
  • This embodiment is not limited to the functions of front-end applications, third-party applications, and back-end systems.
  • the specific form and content of the interface call request are not limited, and the settings are specifically set according to actual needs.
  • the start signal of the request will be automatically triggered, so that the back end can automatically capture the start timing of the interface call request.
  • Step S120 if the start signal of the interface call request currently exists, trigger the custom middleware to create a custom thread shared variable to record the request information carried in the interface call request; otherwise, continue to step S110;
  • the backend detects the start signal of the interface call request, it triggers the custom middleware to create a custom thread shared variable for use of the thread shared variable to record the request information carried in the interface call request.
  • a custom thread shared variable is created through the custom middleware, and the request information carried in the interface call request is assigned to the variable to achieve information record.
  • the threa.local() method is used to avoid information confusion between multiple threads and errors in the recorded information.
  • the request information of the interface call request recorded by the backend includes: the name of the caller, the IP address of the caller, the name of the calling interface, the request time, and the content of the request.
  • the back-end can not only monitor the back-end performance, but also analyze the user's access preferences or access abnormalities, so as to understand user behavior, optimize or improve the back-end performance, and improve the user experience.
  • Step S130 detecting whether there is an end signal or an abnormal signal of the interface call request currently;
  • the end signal or exception signal of the request when an interface call request ends or an exception occurs, the end signal or exception signal of the request will also be automatically triggered, so that the backend can automatically capture the end timing of the interface call request or Timing of interruption.
  • the interface call request when the interface call request is abnormal, the connection will be interrupted and the request will become invalid.
  • Step S140 If the end signal or abnormal signal of the interface call request currently exists, obtain the request information recorded by the thread shared variable and save it in a preset database, otherwise continue to perform step S130.
  • the recorded request information is read from the thread shared variable, and form fields inserted into the database are constructed, and the request information of the front-end interface call request is saved To the database.
  • the back-end uses the signal mechanism of the django framework to monitor the interface call request initiated by the front-end, and obtain the request information in the front-end interface call, so that the back-end can directly obtain the request information of the front-end interface call.
  • the back-end uses the Django framework, even if the front-end uses other technical frameworks, it will not affect the back-end to record the request information of the interface call, which solves the problem that the back-end cannot directly obtain the request information of the front-end interface call in the front-end separation framework.
  • this embodiment further reduces the system overhead when the back-end obtains interface call request information.
  • FIG. 3 is a schematic flowchart of a second embodiment of the interface call recording method based on the Django framework of this application. Based on the foregoing embodiment, in this embodiment, before the foregoing step S110, the method further includes:
  • Step S210 setting the custom middleware and the signal processing function corresponding to each interface call request, and binding each signal processing function with the corresponding signal;
  • the django framework supports middleware customization. Therefore, in order to realize the interface call recording function, it is necessary to customize the middleware in advance, and specifically customize the function methods in the middleware to create through the functions in the custom middleware A custom thread shared variable.
  • the django framework also supports signal function customization.
  • the following request signals are built in the django framework:
  • request_started, request start signal which is automatically triggered when the request comes
  • request_finished, request end signal which is automatically triggered when the request ends
  • the signal processing function is used to record and save the request information carried in the interface call request.
  • Step S220 Register the custom middleware and each signal processing function in the local configuration file, where the signals include: the start signal, the end signal and the abnormal signal of the interface call request.
  • the method of combining the middleware and signal mechanism of the Django framework is used to record user activities. Therefore, the middleware and custom signals are customized in the backend Handle the function and bind the signal processing function to the corresponding signal. For example, bind different pre-defined signal processing functions to the corresponding request_started signal, Request_fineshed signal, and got_request_exception signal. Finally, the custom middleware and Each signal processing function is registered in the configuration file of the back-end system. When the back-end system starts, the configuration file will be automatically loaded, so as to realize the automatic recording of interface call request information.
  • step S120 specifically includes:
  • start signal of the interface call request currently exists, trigger the custom middleware to create a custom thread shared variable, and trigger the execution of the signal processing function bound to the start signal.
  • the custom middleware when an interface call request occurs, the custom middleware will be triggered to create a custom thread shared variable, and the start signal of the interface call request will be automatically triggered, and the execution will be triggered through the signal mechanism The signal processing function bound to the start signal.
  • the signal processing function bound to the start signal is triggered to execute, and the signal processing function is used to determine whether the calling method is the post method. If not, skip directly, if it is post Method, the request information submitted through the post method is copied to the thread shared variable.
  • the entire request information recording process is automatically detected and recorded by the back-end system based on the django framework, which realizes that the back-end can directly obtain the request information of the interface call.
  • the signal mechanism of the Django framework is used. Request message records, thus reducing the overhead of the back-end system accordingly.
  • step S140 specifically includes:
  • the end signal or exception signal is automatically triggered, and then the signal processing function bound to the end signal or exception signal is triggered to perform related processing.
  • the signal processing function bound to the execution end signal or abnormal signal is triggered.
  • the signal processing function first read from the custom thread shared variable Take the pre-recorded request information, and then use the request information as user activity information and save it in the database according to the preset field format.
  • the entire process of recording and saving request information is automatically detected, recorded and saved by the back-end system based on the django framework, which realizes that the back-end can directly obtain the request information for interface calls.
  • the signal mechanism for request message recording it also reduces the overhead of the back-end system accordingly.
  • FIG. 4 is a schematic flowchart of a third embodiment of the interface call recording method based on the Django framework of this application. Based on the foregoing embodiment, in this embodiment, after the foregoing step S140, the method further includes:
  • Step S310 create a data processing task, and configure the data processing mode and data processing fields
  • the data processing method is bound to the data processing field of the data.
  • the data processing task is realized through a third party or a plug-in, and the third party or the plug-in only controls the bound data.
  • the raw data corresponding to the processing field is statistically processed.
  • the data processing method refers to the method in which the original data is processed, such as statistical sum and statistical mean.
  • the data processing field specifically refers to the table field of the data table where the original data is stored in the database.
  • the recorded request information is stored in the database in the form of a data table as the original data.
  • different interface callers or different calling interface names correspond to a data table, and each data table contains multiple data fields, such as the name of the caller, the IP address of the caller, the name of the calling interface, the request time, and Request content, etc.
  • Step S320 Execute the data processing task to read corresponding original data from the database based on the data processing field, and call the data processing plug-in corresponding to the data processing mode to process the original data, The processing data is obtained and stored in the database.
  • the data processing plug-in when performing data processing tasks, first read the corresponding original data from the database based on the configured data processing fields, and then call the data processing plug-in corresponding to the specified data processing mode to process the original data. And get the corresponding processing data. For example, count the number of calls made by the same interface in the same time period, count the number of calls made by the same IP address, etc.
  • the data processing plug-in performs logical processing on the original data. For example, the interface calling time 9:05, 10:10, 10:38 is processed into the interface calling time period 9:00 ⁇ 11:00, the calling interface name A and B are processed into access service type 1, and the interface name E, F processing is access service type 2.
  • processing data is essentially intermediate data and not the final data seen by the user, so the processing data needs to be stored in the database again for further processing.
  • This embodiment encapsulates the statistical analysis method of the original request information stored in the database into a data processing plug-in, and the data processing plug-in is only responsible for processing the data according to the set processing mode without identifying the specific meaning of the data, so it is called with the interface Party has nothing to do.
  • the back-end only needs to bind the data processing plug-in to the corresponding data processing field by configuring the data processing mode of the data processing task, thereby realizing the decoupling of the data processing method and the interface caller, ensuring the independence of the back-end operation And stability.
  • FIG. 5 is a flowchart of a fourth embodiment of the interface call recording method based on the Django framework of this application. Based on the foregoing embodiment, in this embodiment, after the foregoing step S320, the method further includes:
  • Step S330 Create a data report, and configure the data source, statistical time range, statistical object, and data display mode corresponding to the data report;
  • the back-end in order to facilitate the back-end to understand the behavior of the front-end user, the back-end further displays the collected data in a report to analyze the behavior of the front-end user through the report.
  • the data source refers to the data source of the data report, specifically the processing data generated after the data processing task is executed;
  • the statistical time range refers to the time range corresponding to the request time;
  • the statistical object specifically includes the name of the caller, the caller IP address, calling interface name;
  • data display mode is used to specify the packaging method and output data format of the data, which specifically refers to the method or dimension in which the data is displayed, such as display according to trend, display according to device ranking, etc., which is implemented through the corresponding plug-in
  • the data is packed and converted into a specific format for output.
  • Step S340 using the statistical time range and the statistical object as data screening conditions, read processing data corresponding to the data source and meeting the data screening conditions from the database;
  • step S350 the data display plug-in corresponding to the data display mode is called to package the read processing data, and the report data is obtained and output and displayed.
  • the backend displays the data by configuring a data report.
  • the data report uses the result of a data processing task as the data source, filters the data by time range and specific statistical objects, and then filters the data by data display.
  • the data is packaged and output so that managers can intuitively understand the situation of statistical objects.
  • the backend also supports exporting the generated report data in a specified format (such as pdf, excel, etc.) to facilitate other applications.
  • a specified format such as pdf, excel, etc.
  • the application also provides an interface call recording device based on the django framework.
  • FIG. 6 is a schematic diagram of functional modules of an embodiment of an interface call recording device based on the Django framework of the present application.
  • the interface call recording device based on the django framework includes:
  • the detection module 10 is used to detect whether there is a start signal of an interface call request initiated by the front end; and whether there is an end signal or an abnormal signal of the interface call request;
  • the recording module 20 is configured to trigger the custom middleware to create a custom thread shared variable if the start signal of the interface call request currently exists, so as to record the request information carried in the interface call request;
  • the saving module 30 is configured to, if the end signal or abnormal signal of the interface call request currently exists, obtain the request information recorded by the thread shared variable and save it in a preset database.
  • the interface call recording device uses the signal mechanism of the django framework to monitor the interface call request initiated by the front end, and obtain the request information in the front-end interface call, so that the interface call recording device can directly obtain the request information of the front-end interface call .
  • the interface call recording device uses the Django framework, even if the front-end uses other technical frameworks, it will not affect the back-end recording interface call request information, which solves the problem that the back-end cannot directly obtain the front-end interface call request information in the front-end separation framework. problem.
  • this embodiment further reduces the system overhead when the back-end obtains interface call request information.
  • the application also provides a non-volatile computer-readable storage medium.
  • an interface call recording program is stored on the non-volatile computer-readable storage medium, and when the interface call recording program is executed by a processor, the Django-based framework as described in any of the above embodiments is implemented
  • the interface calls the steps of the recording method.
  • the method implemented when the interface call recording program is executed by the processor can refer to the various embodiments of the interface call recording method based on the django framework of this application, so it will not be repeated.
  • the interface call recording program when executed by the processor, the following steps of the interface call recording method based on the django framework are implemented:
  • the request information recorded by the thread shared variable is acquired and saved in a preset database.
  • the following steps of the interface call recording method based on the Django framework are further implemented:
  • the following steps of the interface call recording method based on the Django framework are further implemented:
  • start signal of the interface call request currently exists, trigger the custom middleware to create a custom thread shared variable, and trigger the execution of the signal processing function bound to the start signal;
  • the following steps of the interface call recording method based on the Django framework are further implemented:
  • the request information is used as user activity information and stored in the database according to a preset field format.
  • the following steps of the interface call recording method based on the Django framework are further implemented:
  • the following steps of the interface call recording method based on the Django framework are further implemented:
  • the data display plug-in corresponding to the data display mode is called to package the read processing data, and the report data is obtained and output and displayed.
  • the method of the above embodiments can be implemented by means of software plus the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better. ⁇
  • the technical solution of this application essentially or the part that contributes to the existing technology can be embodied in the form of a software product.
  • the computer software product is stored in a storage medium (such as ROM/RAM), including Several instructions are used to make a terminal (which may be a mobile phone, a computer, a server, or a network device, etc.) execute the method described in each embodiment of the present application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Telephonic Communication Services (AREA)

Abstract

一种基于django框架的接口调用记录方法,包括以下步骤:检测当前是否存在前端发起的接口调用请求的开始信号(S110);若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息(S120);检测当前是否存在所述接口调用请求的结束信号或异常信号(S130);若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中(S140)。该方法使得后端可以直接获取到接口调用的请求信息,提升了接口调用记录的便捷性。

Description

基于django框架的接口调用记录方法、装置、设备及存储介质
本申请要求于2019年4月4日提交中国专利局、申请号为201910269322.9、发明名称为“基于django框架的接口调用记录方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在申请中。
技术领域
本申请涉及大数据技术领域,尤其涉及一种基于django框架的接口调用记录方法、装置、设备及计算机可读存储介质。
背景技术
随着智能终端技术的快速发展,越来越多的终端应用被开发。以Android操作系统为例,由于Android系统的开源性,基于Android系统进行开发的第三方应用种类繁多。通常应用程序在启动之后,应用程序的所有进程都在用户终端上运行,前端的用户操作行为在后端是不可见的。
为更好地了解和分析用户行为,进而提升用户体验,因此,应用程序运营方需要在后端获得前端的用户操作行为,而前端的用户操作行为具体可通过前端向后端发起的接口调用请求进行分析得到,也即后端需要记录前端的接口调用请求信息。现有技术中,发明人意识到通常都是先由前端记录接口调用的请求信息并生成日志,然后再将日志上传后端,因而后端并不能直接获得前端接口调用的请求信息,也即存在记录接口调用的请求信息不够便捷。
发明内容
本申请的主要目的在于提供一种基于django框架的接口调用记录方法、装置、设备及计算机可读存储介质,旨在解决现有技术记录接口调用的请求信息不够便捷的技术问题。
为实现上述目的,本申请提供一种基于django框架的接口调用记录方法,其特征在于,所述基于django框架的接口调用记录方法包括以下步骤:
检测当前是否存在前端发起的接口调用请求的开始信号;
若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
检测当前是否存在所述接口调用请求的结束信号或异常信号;
若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
可选地,在所述检测当前是否存在前端发起的接口调用请求的开始信号的步骤之前,还包括:
设置自定义中间件以及各接口调用请求对应的信号处理函数,并将各信号处理函数与对应信号进行绑定;
将自定义中间件以及各信号处理函数注册到本地配置文件中,其中,所述信号包括:接口调用请求的开始信号、结束信号以及异常信号。
可选地,所述若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息包括:
若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,并触发执行与所述开始信号绑定的信号处理函数;
其中,通过执行与所述开始信号绑定的信号处理函数,以执行以下操作:
检测当前接口调用请求是否采用post方法;
若是,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
可选地,所述若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中包括:
若当前存在所述接口调用请求的结束信号,则触发执行与所述结束信号绑定的信号处理函数;
若当前存在所述接口调用请求的异常信号,则触发执行与所述异常信号绑定的信号处理函数;
其中,通过执行与所述结束号或所述异常信号绑定的信号处理函数,以执行以下操作:
从所述线程共享变量中读取请求信息;
将所述请求信息作为用户活动信息并按照预置字段格式保存到所述数据库中。
可选地,所述请求信息包括:调用方名称、调用方IP地址、调用接口名称、请求时间以及请求内容。
可选地,在所述若当前存在所述接口调用请求的结束信号或异常信号, 则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中的步骤之后,还包括:
创建数据加工任务,并配置数据加工方式与数据加工字段;
执行所述数据加工任务,以基于所述数据加工字段,从所述数据库中读取对应原始数据,以及调用与所述数据加工方式对应的数据加工插件对所述原始数据进行加工,得到加工数据并存入所述数据库中。
可选地,在所述执行所述数据加工任务的步骤之后,还包括:
创建数据报表,并配置所述数据报表对应的数据源、统计时间范围、统计对象以及数据展现方式;
以所述统计时间范围与统计对象为数据筛选条件,从所述数据库中读取与所述数据源对应且符合所述数据筛选条件的加工数据;
调用与所述数据展现方式对应的数据展现插件对读取的加工数据进行包装,得到报表数据并输出展示。
进一步地,为实现上述目的,本申请还提供一种基于django框架的接口调用记录装置,所述基于django框架的接口调用记录装置包括:
检测模块,用于检测当前是否存在前端发起的接口调用请求的开始信号;以及检测当前是否存在所述接口调用请求的结束信号或异常信号;
记录模块,用于若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
保存模块,用于若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
进一步地,为实现上述目的,本申请还提供一种基于django框架的接口调用记录设备,所述基于django框架的接口调用记录设备包括存储器、处理器以及存储在所述存储器上并可在所述处理器上运行的接口调用记录程序,所述接口调用记录程序被所述处理器执行时实现如上述任一项所述的基于django框架的接口调用记录方法的步骤。
进一步地,为实现上述目的,本申请还提供一种非易失性计算机可读存储介质,所述计算机可读存储介质上存储有接口调用记录程序,所述接口调用记录程序被处理器执行时实现如上述任一项所述的基于django框架的接口调用记录方法的步骤。
本申请中,后端采用django框架的信号机制来监控前端发起的接口调用请求,并获取前端接口调用中的请求信息,进而使得后端可以直接获取到前端接口调用的请求信息。另外,由于后端采用django框架,因而即使前端使用其他技术框架也不会影响后端记录接口调用的请求信息,解决了前后端分离框架中后端无法直接获取前端接口调用的请求信息的问题。此外,本申请还进一步降低了后端获取接口调用请求信息时的系统开销。
附图说明
图1为本申请实施例方案涉及的基于django框架的接口调用记录设备运行环境的结构示意图;
图2为本申请基于django框架的接口调用记录方法第一实施例的流程示意图;
图3为本申请基于django框架的接口调用记录方法第二实施例的流程示意图;
图4为本申请基于django框架的接口调用记录方法第三实施例的流程示意图;
图5为本申请基于django框架的接口调用记录方法第四实施例的流程示意图;
图6为本申请基于django框架的接口调用记录装置一实施例的功能模块示意图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅用以解释本申请,并不用于限定 本申请。
本申请提供一种基于django框架的接口调用记录设备。
参照图1,图1为本申请实施例方案涉及的基于django框架的接口调用记录设备运行环境的结构示意图。
如图1所示,该基于django框架的接口调用记录设备包括:处理器1001,例如CPU,通信总线1002、用户接口1003,网络接口1004,存储器1005。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。
本领域技术人员可以理解,图1中示出的基于django框架的接口调用记录设备的硬件结构并不构成对基于django框架的接口调用记录设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
如图1所示,作为一种计算机可读存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及接口调用记录程序。其中,操作系统是管理和控制基于django框架的接口调用记录设备和软件资源的程序,支持接口调用记录程序以及其它软件和/或程序的运行。
在图1所示的基于django框架的接口调用记录设备的硬件结构中,网络接口1004主要用于接入网络;用户接口1003主要用于侦测确认指令和编辑指令等,而处理器1001可以用于调用存储器1005中存储的接口调用记录程序,并执行以下基于django框架的接口调用记录方法的各实施例的操作。
基于上述基于django框架的接口调用记录设备硬件结构,提出本申请基于django框架的接口调用记录方法的各个实施例。
为便于更好地理解本申请,下面对django框架技术进行简要说明。
django框架是一个基于MVC构造的框架,其包含一个“信号的分发器”,用于在框架执行操作时解耦各种处理动作。当django框架发生动作时将发出 信号,而监听了这个信号的函数就会自动执行。当某事件在框架内发生时,进而可以通知到关联的应用程序。
django内置的信号包括:内置信号、数据库迁移信号、请求和响应的信号、测试信号等。对于内置信号,使用时需要在信号中注册对应的函数,当应用程序执行相应操作时,自动触发注册函数。此外,django还允许自定义信号。对于的django内的信号来说,只需要把想执行的函数注册到信号中,那么当动作发生时对应信号的注册函数便会自动执行。
此外,django框架中的中间件(middleware)在django中其实是一个类,包含有多个成员函数,在请求到来和结束或者发生异常时,django会根据自己的规则在合适时机执行中间件中的相应函数。
参照图2,图2为本申请基于django框架的接口调用记录方法第一实施例的流程示意图。本实施例中,所述基于django框架的接口调用记录方法包括以下步骤:
步骤S110,检测当前是否存在前端发起的接口调用请求的开始信号;
本实施例预先构建了基于django框架后端系统,后端通过django框架实时检测前端或者第三方应用发起的针对后端接口的接口调用请求,比如Http请求。本实施例对于前端应用、第三方应用以及后端系统的功能不限,同时对于接口调用请求的具体形式和内容不限,具体根据实际需要进行设置。
本实施例中,基于django框架的信号机制,当前端向后端发起接口调用请求时,将会自动触发该请求的开始信号,进而使得后端可以自动捕捉到接口调用请求的开始时机。
步骤S120,若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;否则继续执行步骤S110;
本实施例中,若后端检测到接口调用请求的开始信号,则触发自定义中间件创建一自定义的线程共享变量,以供使用该线程共享变量,记录接口调用请求中携带的请求信息。
本实施例中,为便于后端快速记录接口调用的请求信息,因此,通过自定义中间件创建一自定义的线程共享变量,通过将接口调用请求中携带的请求信息赋值给该变量,从而实现信息记录。其中,针对于多线程的前端应用 或第三方应用,为了确保线程安全,使用threa.local()方法以避免多线程之间发生信息混淆而使得记录的信息出现错误。
可选的,在一实施例中,后端记录的接口调用请求的请求信息包括:调用方名称、调用方IP地址、调用接口名称、请求时间以及请求内容。后端基于上述信息,不仅可对后端性能进行监控,并且还可以分析用户的访问偏好或者访问异常,从而了解用户行为,优化或改进后端性能,进而提升用户使用体验。
步骤S130,检测当前是否存在所述接口调用请求的结束信号或异常信号;
本实施例中,基于django框架的信号机制,当接口调用请求结束或发生异常时,同样将会自动触发该请求的结束信号或异常信号,进而使得后端可以自动捕捉到接口调用请求结束时机或者中断时机。其中,当接口调用请求发生异常时,将会导致连接中断和请求失效。
步骤S140,若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中,否则继续执行步骤S130。
本实施例中,若检测到接口调用请求的结束信号或异常信号,则从线程共享变量中读取到记录的请求信息,并构建插入数据库的表格字段,进而将前端接口调用请求的请求信息保存到数据库中。
本实施例中,后端采用django框架的信号机制来监控前端发起的接口调用请求,并获取前端接口调用中的请求信息,进而使得后端可以直接获取到前端接口调用的请求信息。另外,由于后端采用django框架,因而即使前端使用其他技术框架也不会影响后端记录接口调用的请求信息,解决了前后端分离框架中后端无法直接获取前端接口调用的请求信息的问题。此外,本实施例还进一步降低了后端获取接口调用请求信息时的系统开销。
参照图3,图3为本申请基于django框架的接口调用记录方法第二实施例的流程示意图。基于上述实施例,本实施例中,在上述步骤S110之前,还包括:
步骤S210,设置自定义中间件以及各接口调用请求对应的信号处理函数,并将各信号处理函数与对应信号进行绑定;
本实施例中,django框架支持中间件自定义,因此,为实现接口调用记录功能,需要预先自定义中间件,具体自定义中间件中的函数方法,以通过该自定义中间件中的函数创建一自定义线程共享变量。
此外,django框架还支持信号函数自定义,在django框架下内置有如下请求信号request signals:
(1)request_started,请求开始信号,其在请求到来时自动触发;
(2)request_finished,请求结束信号,其在请求结束时自动触发;
(3)got_request_exception,请求异常信号,其在请求异常时自动触发。
本实施例中只需自定义各信号处理函数即可,并将各信号处理函数与对应信号进行绑定。通过信号处理函数以记录和保存接口调用请求中携带的请求信息。
步骤S220,将自定义中间件以及各信号处理函数注册到本地配置文件中,其中,所述信号包括:接口调用请求的开始信号、结束信号以及异常信号。
本实施例中,为实现对接口调用请求信息的自动记录,因此,基于django框架的中间件与信号机制相结合的方法来进行用户活动记录,因此,在后端自定义中间件以及自定义信号处理函数,并将信号处理函数与对应的信号进行绑定,比如将预先自定义的不同信号处理函数与对应的request_started信号、Request_fineshed信号和got_request_exception信号分别进行绑定,最后再将自定义中间件以及各信号处理函数注册到后端系统的配置文件中。当后端系统启动时将自动加载配置文件,从而实现对接口调用请求信息的自动记录。
进一步地,在本申请基于django框架的接口调用记录方法一实施例中,上述步骤S120具体包括:
若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,并触发执行与所述开始信号绑定的信号处理函数。
本实施例中,基于django框架的MVC模型机制,当发生接口调用请求时,会触发自定义中间件创建一自定义线程共享变量,同时还自动触发接口调用请求的开始信号,通过信号机制触发执行与开始信号绑定的信号处理函数。
本实施例中,通过执行与接口调用请求的开始信号绑定的信号处理函数, 以执行以下操作:
(1)检测当前接口调用请求是否采用post方法;
(2)若当前接口调用请求采用post方法,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
本实施例中,当检测到接口调用请求的开始信号时,触发执行开始信号对应绑定的信号处理函数,通过该信号处理函数,判断调用方法是否为post方法,若不是直接跳过,若是post方法,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
本实施例中,整个请求信息的记录过程由基于django框架的后端系统自动完成检测与记录,实现了后端可以直接获取到接口调用的请求信息,同时由于采用Django框架自带的信号机制进行请求消息记录,因而也相应降低了后端系统的开销。
进一步地,在本申请基于django框架的接口调用记录方法一实施例中,上述步骤S140具体包括:
若当前存在所述接口调用请求的结束信号,则触发执行与所述结束信号绑定的信号处理函数;若当前存在所述接口调用请求的异常信号,则触发执行与所述异常信号绑定的信号处理函数;
本实施例中,当接口调用请求结束或发生异常时,会自动触发结束信号或异常信号,进而触发执行与结束信号或异常信号绑定的信号处理函数执行相关处理。
本实施例中,通过执行与所述结束号或所述异常信号绑定的信号处理函数,以执行以下操作:
(1)从所述线程共享变量中读取请求信息;
(2)将所述请求信息作为用户活动信息并按照预置字段格式保存到所述数据库中。
本实施例中,当检测到接口调用请求的结束信号或异常信号时,触发执行结束信号或异常信号对应绑定的信号处理函数,通过该信号处理函数,先从自定义的线程共享变量中读取预先记录的请求信息,然后再将请求信息作为用户活动信息并按照预置字段格式保存到数据库中。
本实施例中,整个请求信息的记录和保存过程都由基于django框架的后端系统自动完成检测、记录与保存,实现了后端可以直接获取到接口调用的请求信息,同时由于采用Django框架自带的信号机制进行请求消息记录,因而也相应降低了后端系统的开销。
参照图4,图4为本申请基于django框架的接口调用记录方法第三实施例的流程示意图。基于上述实施例,本实施例中,在上述步骤S140之后,还包括:
步骤S310,创建数据加工任务,并配置数据加工方式与数据加工字段;
本实施例中,通过创建并配置数据加工任务的方式,将数据加工方式和数据的数据加工字段进行绑定,比如通过第三方或插件实现数据加工任务,第三方或插件只对绑定的数据加工字段对应的原始数据进行统计处理。
数据加工方式是指以何种方式来加工原始数据,比如统计总和、统计均值等。数据加工字段具体指存储到数据库中原始数据所在数据表的表字段。记录的请求信息作为原始数据以数据表形式存储在数据库中。例如,不同的接口调用方或不同的调用接口名称对应一张数据表,每一张数据表包含多个数据字段,比如字段名称为调用方名称、调用方IP地址、调用接口名称、请求时间以及请求内容等。
步骤S320,执行所述数据加工任务,以基于所述数据加工字段,从所述数据库中读取对应原始数据,以及调用与所述数据加工方式对应的数据加工插件对所述原始数据进行加工,得到加工数据并存入所述数据库中。
本实施例中,在执行数据加工任务时,先基于配置的数据加工字段,从数据库中读取对应的原始数据,然后再调用与指定的数据加工方式对应的数据加工插件对原始数据进行加工,并得到对应的加工数据。例如,统计同一接口在同一时间段内的调用次数、统计同一IP地址调用接口的次数等。另外,数据加工插件对原始数据进行逻辑加工。比如将接口调用时间9:05、10:10、10:38加工为接口调用时间段9:00~11:00,将调用接口名称A、B加工为访问业务类型1,将调用接口名称E、F加工为访问业务类型2。
需要说明的是,该加工数据实质为中间数据而并非用户看到的最终数据,因而需要将加工数据再次存入数据库中,以待进一步处理。
本实施例将对数据库中存储的原始请求信息的统计分析方法封装成数据加工插件,并且数据加工插件只负责根据设置的加工方式对数据进行加工处理而不识别数据的具体意义,因而与接口调用方无关。后端只需通过配置数据加工任务的数据加工方式而将数据加工插件与对应数据加工字段进行绑定,进而实现了数据数据加工方式与接口调用方的解耦,保证了后端运行的独立性与稳定性。
参照图5,图5为本申请基于django框架的接口调用记录方法第四实施例的流程示意图。基于上述实施例,本实施例中,在上述步骤S320之后,还包括:
步骤S330,创建数据报表,并配置所述数据报表对应的数据源、统计时间范围、统计对象以及数据展现方式;
本实施例中,为便于后端了解前端用户行为情况,后端还进一步对采集的数据进行报表展现,以供通过报表分析前端用户的行为。
本实施例中,数据源是指数据报表的数据来源,具体为执行数据加工任务后所生成的加工数据;统计时间范围是指请求时间对应的时间范围;统计对象具体包括调用方名称、调用方IP地址、调用接口名称;数据展现方式用于规定数据的包装方式和输出数据格式,具体指数据以什么方式或维度来展现,比如按照趋势展现、按照设备排名展现等,具体通过对应的插件实现数据包装并转换为特定格式输出。
步骤S340,以所述统计时间范围与统计对象为数据筛选条件,从所述数据库中读取与所述数据源对应且符合所述数据筛选条件的加工数据;
步骤S350,调用与所述数据展现方式对应的数据展现插件对读取的加工数据进行包装,得到报表数据并输出展示。
本实施例中,后端通过以配置数据报表的方式对数据进行展示,数据报表以数据加工任务的结果为数据源,通过时间范围和具体的统计对象来筛选数据,然后通过数据展现方式对筛选数据进行包装输出,从而便于管理人员直观了解统计对象的情况。
本实施例中,后端还支持将生成的报表数据以指定格式(比如pdf、excel等)导出而便于进行其他运用。
本申请还提供一种基于django框架的接口调用记录装置。
参照图6,图6为本申请基于django框架的接口调用记录装置一实施例的功能模块示意图。本实施例中,基于django框架的接口调用记录装置包括:
检测模块10,用于检测当前是否存在前端发起的接口调用请求的开始信号;以及检测当前是否存在所述接口调用请求的结束信号或异常信号;
记录模块20,用于若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
保存模块30,用于若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
基于与上述本申请基于django框架的接口调用记录方法相同的实施例说明内容,因此本实施例对基于django框架的接口调用记录装置的实施例内容不做过多赘述。
本实施例中,接口调用记录装置采用django框架的信号机制来监控前端发起的接口调用请求,并获取前端接口调用中的请求信息,进而使得接口调用记录装置可以直接获取到前端接口调用的请求信息。另外,由于接口调用记录装置采用django框架,因而即使前端使用其他技术框架也不会影响后端记录接口调用的请求信息,解决了前后端分离框架中后端无法直接获取前端接口调用的请求信息的问题。此外,本实施例还进一步降低了后端获取接口调用请求信息时的系统开销。
本申请还提供一种非易失性计算机可读存储介质。
本实施例中,所述非易失性计算机可读存储介质上存储有接口调用记录程序,所述接口调用记录程序被处理器执行时实现如上述任一项实施例中所述的基于django框架的接口调用记录方法的步骤。其中,接口调用记录程序被处理器执行时所实现的方法可参照本申请基于django框架的接口调用记录方法的各个实施例,因此不再过多赘述。
可选的,在一具体实施例中,所述接口调用记录程序被处理器执行时实现如下基于django框架的接口调用记录方法的步骤:
检测当前是否存在前端发起的接口调用请求的开始信号;
若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
检测当前是否存在所述接口调用请求的结束信号或异常信号;
若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
可选的,在一具体实施例中,所述接口调用记录程序被处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
设置自定义中间件以及各接口调用请求对应的信号处理函数,并将各信号处理函数与对应信号进行绑定;
将自定义中间件以及各信号处理函数注册到本地配置文件中,其中,所述信号包括:接口调用请求的开始信号、结束信号以及异常信号。
可选的,在一具体实施例中,所述接口调用记录程序被处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,并触发执行与所述开始信号绑定的信号处理函数;
其中,通过执行与所述开始信号绑定的信号处理函数,以执行以下操作:
检测当前接口调用请求是否采用post方法;
若是,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
可选的,在一具体实施例中,所述接口调用记录程序被处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
若当前存在所述接口调用请求的结束信号,则触发执行与所述结束信号绑定的信号处理函数;
若当前存在所述接口调用请求的异常信号,则触发执行与所述异常信号绑定的信号处理函数;
其中,通过执行与所述结束号或所述异常信号绑定的信号处理函数,以执行以下操作:
从所述线程共享变量中读取请求信息;
将所述请求信息作为用户活动信息并按照预置字段格式保存到所述数据库中。
可选的,在一具体实施例中,所述接口调用记录程序被处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
创建数据加工任务,并配置数据加工方式与数据加工字段;
执行所述数据加工任务,以基于所述数据加工字段,从所述数据库中读取对应原始数据,以及调用与所述数据加工方式对应的数据加工插件对所述原始数据进行加工,得到加工数据并存入所述数据库中。
可选的,在一具体实施例中,所述接口调用记录程序被处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
创建数据报表,并配置所述数据报表对应的数据源、统计时间范围、统计对象以及数据展现方式;
以所述统计时间范围与统计对象为数据筛选条件,从所述数据库中读取与所述数据源对应且符合所述数据筛选条件的加工数据;
调用与所述数据展现方式对应的数据展现插件对读取的加工数据进行包装,得到报表数据并输出展示。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器或者网络设备等)执行本申请各个实施例所述的方法。
上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,这些均属于本申请的保护之内。

Claims (20)

  1. 一种基于django框架的接口调用记录方法,所述基于django框架的接口调用记录方法包括以下步骤:
    检测当前是否存在前端发起的接口调用请求的开始信号;
    若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
    检测当前是否存在所述接口调用请求的结束信号或异常信号;
    若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
  2. 如权利要求1所述的基于django框架的接口调用记录方法,在所述检测当前是否存在前端发起的接口调用请求的开始信号的步骤之前,还包括:
    设置自定义中间件以及各接口调用请求对应的信号处理函数,并将各信号处理函数与对应信号进行绑定;
    将自定义中间件以及各信号处理函数注册到本地配置文件中,其中,所述信号包括:接口调用请求的开始信号、结束信号以及异常信号。
  3. 如权利要求2所述的基于django框架的接口调用记录方法,所述若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息包括:
    若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,并触发执行与所述开始信号绑定的信号处理函数;
    其中,通过执行与所述开始信号绑定的信号处理函数,以执行以下操作:
    检测当前接口调用请求是否采用post方法;
    若是,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
  4. 如权利要求3所述的基于django框架的接口调用记录方法,所述若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中包括:
    若当前存在所述接口调用请求的结束信号,则触发执行与所述结束信号绑定的信号处理函数;
    若当前存在所述接口调用请求的异常信号,则触发执行与所述异常信号绑定的信号处理函数;
    其中,通过执行与所述结束号或所述异常信号绑定的信号处理函数,以执行以下操作:
    从所述线程共享变量中读取请求信息;
    将所述请求信息作为用户活动信息并按照预置字段格式保存到所述数据库中。
  5. 如权利要求1所述的基于django框架的接口调用记录方法,所述请求信息包括:调用方名称、调用方IP地址、调用接口名称、请求时间以及请求内容。
  6. 如权利要求5所述的基于django框架的接口调用记录方法,在所述若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中的步骤之后,还包括:
    创建数据加工任务,并配置数据加工方式与数据加工字段;
    执行所述数据加工任务,以基于所述数据加工字段,从所述数据库中读取对应原始数据,以及调用与所述数据加工方式对应的数据加工插件对所述原始数据进行加工,得到加工数据并存入所述数据库中。
  7. 如权利要求6所述的基于django框架的接口调用记录方法,在所述执行所述数据加工任务的步骤之后,还包括:
    创建数据报表,并配置所述数据报表对应的数据源、统计时间范围、统计对象以及数据展现方式;
    以所述统计时间范围与统计对象为数据筛选条件,从所述数据库中读取与所述数据源对应且符合所述数据筛选条件的加工数据;
    调用与所述数据展现方式对应的数据展现插件对读取的加工数据进行包装,得到报表数据并输出展示。
  8. 一种基于django框架的接口调用记录装置,所述基于django框架的接口调用记录装置包括:
    检测模块,用于检测当前是否存在前端发起的接口调用请求的开始信号;以及检测当前是否存在所述接口调用请求的结束信号或异常信号;
    记录模块,用于若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
    保存模块,用于若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
  9. 如权利要求8所述的基于django框架的接口调用记录装置,所述基于django框架的接口调用记录装置还包括:
    设置模块,用于设置自定义中间件以及各接口调用请求对应的信号处理函数,并将各信号处理函数与对应信号进行绑定;将自定义中间件以及各信号处理函数注册到本地配置文件中,其中,所述信号包括:接口调用请求的开始信号、结束信号以及异常信号。
  10. 如权利要求9所述的基于django框架的接口调用记录装置,所述记录模块具体用于:
    若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,并触发执行与所述开始信号绑定的信号处理函数;
    其中,通过执行与所述开始信号绑定的信号处理函数,以执行以下操作:
    检测当前接口调用请求是否采用post方法;
    若是,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
  11. 如权利要求10所述的基于django框架的接口调用记录装置,所述保存模块具体用于:
    若当前存在所述接口调用请求的结束信号,则触发执行与所述结束信号绑定的信号处理函数;若当前存在所述接口调用请求的异常信号,则触发执 行与所述异常信号绑定的信号处理函数;
    其中,通过执行与所述结束号或所述异常信号绑定的信号处理函数,以执行以下操作:
    从所述线程共享变量中读取请求信息;
    将所述请求信息作为用户活动信息并按照预置字段格式保存到所述数据库中。
  12. 如权利要求8所述的基于django框架的接口调用记录装置,所述基于django框架的接口调用记录装置还包括:
    数据加工模块,用于创建数据加工任务,并配置数据加工方式与数据加工字段;执行所述数据加工任务,以基于所述数据加工字段,从所述数据库中读取对应原始数据,以及调用与所述数据加工方式对应的数据加工插件对所述原始数据进行加工,得到加工数据并存入所述数据库中。
  13. 如权利要求12所述的基于django框架的接口调用记录装置,所述基于django框架的接口调用记录装置还包括:
    报表展示模块,用于创建数据报表,并配置所述数据报表对应的数据源、统计时间范围、统计对象以及数据展现方式;以所述统计时间范围与统计对象为数据筛选条件,从所述数据库中读取与所述数据源对应且符合所述数据筛选条件的加工数据;调用与所述数据展现方式对应的数据展现插件对读取的加工数据进行包装,得到报表数据并输出展示。
  14. 一种基于django框架的接口调用记录设备,所述基于django框架的接口调用记录设备包括存储器、处理器以及存储在所述存储器上并可在所述处理器上运行的接口调用记录程序,所述接口调用记录程序被所述处理器执行时实现如下基于django框架的接口调用记录方法的步骤:
    检测当前是否存在前端发起的接口调用请求的开始信号;
    若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
    检测当前是否存在所述接口调用请求的结束信号或异常信号;
    若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
  15. 如权利要求14所述的基于django框架的接口调用记录设备,所述接口调用记录程序被所述处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
    设置自定义中间件以及各接口调用请求对应的信号处理函数,并将各信号处理函数与对应信号进行绑定;
    将自定义中间件以及各信号处理函数注册到本地配置文件中,其中,所述信号包括:接口调用请求的开始信号、结束信号以及异常信号。
  16. 如权利要求15所述的基于django框架的接口调用记录设备,所述接口调用记录程序被所述处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
    若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,并触发执行与所述开始信号绑定的信号处理函数;
    其中,通过执行与所述开始信号绑定的信号处理函数,以执行以下操作:
    检测当前接口调用请求是否采用post方法;
    若是,则将通过post方法提交的请求信息拷贝到所述线程共享变量中。
  17. 如权利要求16所述的基于django框架的接口调用记录设备,所述接口调用记录程序被所述处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
    若当前存在所述接口调用请求的结束信号,则触发执行与所述结束信号绑定的信号处理函数;
    若当前存在所述接口调用请求的异常信号,则触发执行与所述异常信号绑定的信号处理函数;
    其中,通过执行与所述结束号或所述异常信号绑定的信号处理函数,以执行以下操作:
    从所述线程共享变量中读取请求信息;
    将所述请求信息作为用户活动信息并按照预置字段格式保存到所述数据库中。
  18. 如权利要求14所述的基于django框架的接口调用记录设备,所述接口调用记录程序被所述处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
    创建数据加工任务,并配置数据加工方式与数据加工字段;
    执行所述数据加工任务,以基于所述数据加工字段,从所述数据库中读取对应原始数据,以及调用与所述数据加工方式对应的数据加工插件对所述原始数据进行加工,得到加工数据并存入所述数据库中。
  19. 如权利要求18所述的基于django框架的接口调用记录设备,所述接口调用记录程序被所述处理器执行时还实现如下基于django框架的接口调用记录方法的步骤:
    创建数据报表,并配置所述数据报表对应的数据源、统计时间范围、统计对象以及数据展现方式;
    以所述统计时间范围与统计对象为数据筛选条件,从所述数据库中读取与所述数据源对应且符合所述数据筛选条件的加工数据;
    调用与所述数据展现方式对应的数据展现插件对读取的加工数据进行包装,得到报表数据并输出展示。
  20. 一种非易失性计算机可读存储介质,所述计算机可读存储介质上存储有接口调用记录程序,所述接口调用记录程序被处理器执行时实现如下基于django框架的接口调用记录方法的步骤:
    检测当前是否存在前端发起的接口调用请求的开始信号;
    若当前存在所述接口调用请求的开始信号,则触发自定义中间件创建一自定义线程共享变量,以记录接口调用请求中携带的请求信息;
    检测当前是否存在所述接口调用请求的结束信号或异常信号;
    若当前存在所述接口调用请求的结束信号或异常信号,则获取所述线程共享变量记录的所述请求信息并保存到预置数据库中。
PCT/CN2019/102218 2019-04-04 2019-08-23 基于django框架的接口调用记录方法、装置、设备及存储介质 WO2020199469A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910269322.9A CN110333954B (zh) 2019-04-04 2019-04-04 基于django框架的接口调用记录方法、装置、设备及存储介质
CN201910269322.9 2019-04-04

Publications (1)

Publication Number Publication Date
WO2020199469A1 true WO2020199469A1 (zh) 2020-10-08

Family

ID=68140115

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/102218 WO2020199469A1 (zh) 2019-04-04 2019-08-23 基于django框架的接口调用记录方法、装置、设备及存储介质

Country Status (2)

Country Link
CN (1) CN110333954B (zh)
WO (1) WO2020199469A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117648211A (zh) * 2024-01-29 2024-03-05 山东云海国创云计算装备产业创新中心有限公司 人工智能框架的运行时统一接口、服务器及调用方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160314501A1 (en) * 2015-03-24 2016-10-27 Mxm Nation Inc. Scalable networked computing system for scoring user influence in an internet-based social network
CN107391278A (zh) * 2017-07-25 2017-11-24 郑州云海信息技术有限公司 一种基于共享内存的前后端通信方法
CN108959455A (zh) * 2018-06-15 2018-12-07 上海陆家嘴国际金融资产交易市场股份有限公司 单页Web应用实现方法、装置、计算机设备和存储介质
CN108958927A (zh) * 2018-05-31 2018-12-07 康键信息技术(深圳)有限公司 容器应用的部署方法、装置、计算机设备和存储介质
CN109508298A (zh) * 2018-12-25 2019-03-22 网易(杭州)网络有限公司 图形化的脚本测试方法及系统

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9116906B2 (en) * 2012-06-12 2015-08-25 Sap Se Centralized read access logging
CN104598513B (zh) * 2014-11-03 2018-05-01 腾讯科技(成都)有限公司 一种基于网页框架的数据流控制方法和系统
CN105787317B (zh) * 2016-03-23 2021-07-13 中国电力科学研究院 基于多层分级系统的权限控制方法
CN108762955A (zh) * 2018-05-30 2018-11-06 平安普惠企业管理有限公司 接口调用方法、装置、计算机设备及存储介质
CN109309712B (zh) * 2018-09-07 2022-06-17 平安科技(深圳)有限公司 基于接口异步调用的数据传输方法、服务器及存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160314501A1 (en) * 2015-03-24 2016-10-27 Mxm Nation Inc. Scalable networked computing system for scoring user influence in an internet-based social network
CN107391278A (zh) * 2017-07-25 2017-11-24 郑州云海信息技术有限公司 一种基于共享内存的前后端通信方法
CN108958927A (zh) * 2018-05-31 2018-12-07 康键信息技术(深圳)有限公司 容器应用的部署方法、装置、计算机设备和存储介质
CN108959455A (zh) * 2018-06-15 2018-12-07 上海陆家嘴国际金融资产交易市场股份有限公司 单页Web应用实现方法、装置、计算机设备和存储介质
CN109508298A (zh) * 2018-12-25 2019-03-22 网易(杭州)网络有限公司 图形化的脚本测试方法及系统

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117648211A (zh) * 2024-01-29 2024-03-05 山东云海国创云计算装备产业创新中心有限公司 人工智能框架的运行时统一接口、服务器及调用方法
CN117648211B (zh) * 2024-01-29 2024-05-24 山东云海国创云计算装备产业创新中心有限公司 人工智能框架的运行时统一接口、服务器及调用方法

Also Published As

Publication number Publication date
CN110333954A (zh) 2019-10-15
CN110333954B (zh) 2024-02-23

Similar Documents

Publication Publication Date Title
US10838838B2 (en) Method and apparatus for dealing with abnormality of application program and storage medium
US9720643B2 (en) Audio management method and apparatus
CN111104315A (zh) 一种测试脚本生成方法及装置、计算机可读存储介质
CN107948744B (zh) 接口检测方法、接口检测设备及计算机可读存储介质
CN110351436B (zh) FreeSWITCH监控方法、设备、存储介质及装置
CN108804215B (zh) 一种任务处理方法、装置以及电子设备
CN110875858B (zh) 应用测试数据抓取方法、系统、设备及存储介质
CN109344066B (zh) 一种浏览器页面的测试方法、系统及终端
CN110287053B (zh) 分布式系统异常统一处理的方法
CN105607986A (zh) 用户行为日志数据采集方法及装置
WO2018210179A1 (zh) 一种应用页面的处理方法、装置及存储介质
CN106919377B (zh) 确定应用程序的展示界面是否是白屏的方法及装置
WO2017206476A1 (zh) 一种cpu占用的检测方法、装置及设备
CN111045879A (zh) 压力测试报告的生成方法、装置及存储介质
CN111064610B (zh) 日志文件的订阅方法、终端设备及存储介质
WO2020199469A1 (zh) 基于django框架的接口调用记录方法、装置、设备及存储介质
JP6238221B2 (ja) ソフトウェアの実行を監視する装置、方法およびプログラム
WO2020077681A1 (zh) 一种延迟加载js脚本的方法和装置
CN103699485A (zh) 应用程序调试方法和装置
CN111176869B (zh) 超时检测方法、装置、设备及存储介质
JP2004094374A (ja) ロギングシステム
CN115828256A (zh) 一种越权与未授权逻辑漏洞检测方法
CN110874303B (zh) 数据采集方法、装置以及设备
CN114741325B (zh) 一种应用系统测试用的测试脚本的录制方法以及装置
CN110908820A (zh) 一种异步任务的执行方法、装置、设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19922604

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19922604

Country of ref document: EP

Kind code of ref document: A1