Disclosure of Invention
In order to solve the above technical problems, embodiments of the present invention are intended to provide a flow statistical method, a device and a system, so as to solve the problems that the existing flow statistical method has high operation complexity and cannot be used in combination with an automated test.
The technical scheme of the invention is realized as follows:
the embodiment of the invention provides a traffic statistical method, which comprises the following steps:
the method comprises the steps of obtaining a push information request sent by a target equipment client, wherein the push information request comprises: the address of the target server and the request type;
acquiring response data returned by the target server according to the push information request;
and counting the flow according to the push information request and the response data.
In the foregoing solution, the obtaining a push information request sent by a target device client includes:
acquiring an IP address of the terminal equipment and binding the target equipment;
and starting a monitoring program, and monitoring the push information request sent by the client on the target equipment.
In the foregoing solution, the obtaining, according to the push information request, response data returned by the target server includes:
acquiring the IP address of the target server according to the push information request;
connecting the target server and sending the push information request to the target server;
and acquiring response data returned by the target server aiming at different request types according to the request type of the information pushing request.
In the foregoing solution, the obtaining, according to the request type of the information pushing request, response data returned by the target server for different request types includes:
judging whether the request type is an offline pre-information pushing request or not, and if the request type is the offline pre-information pushing request, calculating a first request data length of the offline pre-information pushing request; continuously acquiring response data returned by the target server until the push information request before offline is not acquired any more, and counting all the acquired response data to obtain first response data; creating a first file, and inputting a first preset field of the off-line pre-push information into the first file;
if not, judging whether the request type is an offline push information pause request or not, and if so, calculating a second request data length of the offline push information pause request; continuously acquiring response data returned by the target server until the offline pause push information request is not acquired any more, and counting all the acquired response data to obtain second response data; creating a second file, and inputting a first preset field of the offline pause pushing information into the second file;
otherwise, when the request type is not an off-line pre-push information request and an off-line pause push information request, judging whether the request type is an off-line startup diagram push information request, and if the request type is the off-line startup diagram push information request, calculating a third request data length of the off-line startup diagram push information request; continuously acquiring response data returned by the target server until the offline startup diagram pushing information request is not acquired any more, and counting all the acquired response data to obtain third response data; and inputting a first preset field of the off-line startup picture pushing information into the second file.
In the above scheme, the method further comprises:
when the request type is a non-offline information pushing request, judging whether a first preset field recorded in the first file contains an HTTP (hyper text transport protocol) address of the information pushing request, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
when the response data is a first preset threshold value, creating a third file;
and when the response data is a second preset threshold value, creating a fourth file, and inputting a second preset field of the information pushing request into the fourth file.
In the above scheme, the method further comprises:
and when the request type is a non-offline information pushing request and the first preset field recorded in the first file does not contain the HTTP address, judging whether the first preset field of the third file contains the HTTP address or not, and if so, recording the second preset field of the information pushing request into the fourth file.
In the above scheme, the method further comprises:
when the request type is a non-offline information pushing request, and a first preset field recorded in the first file does not contain the HTTP address and a first preset field of the third file does not contain the HTTP address, judging whether a first preset field recorded in the second file contains the HTTP address or not, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
and when the response data is the second preset threshold, creating a fifth file, and inputting a second preset field of the push information request into the fifth file.
In the foregoing solution, the counting the traffic according to the push information request and the response data includes:
respectively counting the lengths of the first return data, the second return data and the third return data;
respectively counting the data sizes of the fourth file and the fifth file;
and calculating the sum of the first request data length, the second request data length, the third request data length, the first return data length, the second return data length, the third return data length, the data size of the fourth file and the data size of the fifth file to obtain the flow size.
The embodiment of the invention also provides a flow statistic device, which comprises:
an obtaining module, configured to obtain a push information request sent by a target device client, where the push information request includes: the address of the target server and the request type;
the acquisition module is further used for acquiring response data returned by the target server according to the push information request;
and the counting module is used for counting the flow according to the push information request and the response data.
In the foregoing scheme, the obtaining module is specifically configured to:
acquiring an IP address of the terminal equipment and binding the target equipment;
and starting a monitoring program, and monitoring the push information request sent by the client on the target equipment.
In the foregoing scheme, the obtaining module is specifically configured to:
acquiring the IP address of the target server according to the push information request;
connecting the target server and sending the push information request to the target server;
and acquiring response data returned by the target server aiming at different request types according to the request type of the information pushing request.
In the foregoing scheme, the obtaining module is specifically configured to:
judging whether the request type is an offline pre-information pushing request or not, and if the request type is the offline pre-information pushing request, calculating a first request data length of the offline pre-information pushing request; continuously acquiring response data returned by the target server until the push information request before offline is not acquired any more, and counting all the acquired response data to obtain first response data; creating a first file, and inputting a first preset field of the off-line pre-push information into the first file;
if not, judging whether the request type is an offline push information pause request or not, and if so, calculating a second request data length of the offline push information pause request; continuously acquiring response data returned by the target server until the offline pause push information request is not acquired any more, and counting all the acquired response data to obtain second response data; creating a second file, and inputting a first preset field of the offline pause pushing information into the second file;
otherwise, when the request type is not an off-line pre-push information request and an off-line pause push information request, judging whether the request type is an off-line startup diagram push information request, and if the request type is the off-line startup diagram push information request, calculating a third request data length of the off-line startup diagram push information request; continuously acquiring response data returned by the target server until the offline startup diagram pushing information request is not acquired any more, and counting all the acquired response data to obtain third response data; and inputting a first preset field of the off-line startup picture pushing information into the second file.
In the foregoing solution, the obtaining module is further configured to:
when the request type is a non-offline information pushing request, judging whether a first preset field recorded in the first file contains an HTTP (hyper text transport protocol) address of the information pushing request, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
when the response data is a first preset threshold value, creating a third file;
and when the response data is a second preset threshold value, creating a fourth file, and inputting a second preset field of the information pushing request into the fourth file.
In the foregoing solution, the obtaining module is further configured to:
and when the request type is a non-offline information pushing request and the first preset field recorded in the first file does not contain the HTTP address, judging whether the first preset field of the third file contains the HTTP address or not, and if so, recording the second preset field of the information pushing request into the fourth file.
In the foregoing solution, the obtaining module is further configured to:
when the request type is a non-offline information pushing request, and a first preset field recorded in the first file does not contain the HTTP address and a first preset field of the third file does not contain the HTTP address, judging whether a first preset field recorded in the second file contains the HTTP address or not, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
and when the response data is the second preset threshold, creating a fifth file, and inputting a second preset field of the push information request into the fifth file.
In the above scheme, the statistical module is configured to:
respectively counting the lengths of the first return data, the second return data and the third return data;
respectively counting the data sizes of the fourth file and the fifth file;
and calculating the sum of the first request data length, the second request data length, the third request data length, the first return data length, the second return data length, the third return data length, the data size of the fourth file and the data size of the fifth file to obtain the flow size.
The embodiment also provides a traffic statistic system, which includes a client, a server and the traffic statistic apparatus, where the client is configured to send a push information request to the server, and the server is configured to return response data according to the push information request.
The embodiment of the invention provides a traffic statistical method, a device and a system, wherein the method is used for counting the traffic according to a push information request and response data sent by a target equipment client and returned by a target server. The method can automatically count the flow consumed when the client sends various information pushing requests, does not need to manually grab the information requests and response data, greatly reduces the operation complexity of the information pushing flow test, and can be used in combination with the automatic test.
Detailed Description
The technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
The traffic statistical method provided by the embodiment of the invention is suitable for the traffic statistics of the push information in the playing process of the player at the client, for example, the traffic statistics of scenes such as the push information before playing offline, the push information when offline is suspended, the push information of an offline startup diagram and the like at the client.
Fig. 1 is a schematic flow diagram of a first embodiment of a traffic statistic method provided in the present invention, and as shown in fig. 1, an execution subject of this embodiment is a traffic statistic module disposed on a client, or the traffic statistic module may also be disposed on a server, and the method includes:
step 101: acquiring a push information request sent by a target equipment client;
wherein the push information request comprises: the address of the target server and the type of request.
It should be noted that the target device client refers to a player client on the terminal device that needs to be counted, and the target device client is used for sending a push information request; the terminal equipment can be, for example, a personal computer, a mobile phone, an IPad, and the like, and the player includes but is not limited to a youku player, a storm video, and the like; the target server is used for receiving the push information request and carrying out data processing response. The flow statistic module intercepts a push information request sent by a client, wherein the push information request comprises an address of a target server, a request type and other datagram text segments for transmitting request messages, and the like, so that the target server receives the push information request and returns response data.
Step 102: and acquiring response data returned by the target server according to the push information request.
In this step, after intercepting the push information request, the traffic statistics module analyzes and processes the intercepted request information, sends the intercepted request to the target server, and finally respectively obtains response data based on different request types returned by the server according to the request types. Specifically, after catching the information push request, firstly, an object (such as a flag) is created as an identifier, the value is 0, then a loop is established, and data is returned after continuously waiting for the request. If data is returned, the value of flag is set to 1 and all data returned during looping is saved, and if no data is returned, looping is skipped. Thus, all response data returned by the request can be calculated. It should be noted that, in this process, the traffic statistics module also counts data lengths of push information requests of different request types.
Step 103: and counting the flow according to the push information request and the response data.
In this step, the total traffic of the push information request of this time can be obtained according to the previously counted data lengths of the push information requests of different types and the response data length returned by the server.
According to the traffic statistical method, the traffic is counted according to the push information request and the response data by acquiring the push information request sent by the target device client and the response data returned by the target server. The method can automatically count the flow consumed when the client sends various information pushing requests, does not need to manually grab the information requests and response data, greatly reduces the operation complexity of the information pushing flow test, and can be used in combination with the automatic test.
Fig. 2 is a schematic flow chart of a second embodiment of the traffic statistic method provided in the present invention, and as shown in fig. 2, on the basis of the first embodiment, the step 101 of obtaining a push information request sent by a target device client includes:
step 1011: and acquiring the IP address of the terminal equipment and binding the target equipment.
Step 1012: and starting a monitoring program, and monitoring a push information request sent by a client on the target equipment.
The embodiment can bind the target equipment through the IP address of each terminal, thereby effectively monitoring the push information request of the client of the target equipment.
Fig. 3 is a schematic flow chart of a third embodiment of the traffic flow statistical method provided in the present invention, and as shown in fig. 3, on the basis of the first embodiment, step 102 includes:
step 1021: and acquiring the IP address of the target server according to the push information request.
Step 1022: and connecting the target server and sending the push information request to the target server.
Step 1023: and acquiring response data returned by the target server aiming at different request types according to the request type of the information pushing request.
In the embodiment, a flow statistic module intercepts any request sent by a client, analyzes and processes the intercepted request information, and acquires the IP address of a target server; and establishing a socket to be connected to the target server, sending the intercepted request to the target server, and respectively acquiring response data returned by the target server according to different request types.
Further, on the basis of the third embodiment, the step 1023 includes:
judging whether the request type is an offline pre-information pushing request or not, and if the request type is the offline pre-information pushing request, calculating a first request data length of the offline pre-information pushing request; continuously acquiring response data returned by the target server until the push information request before offline is not acquired any more, and counting all the acquired response data to obtain first response data; creating a first file, and inputting a first preset field of the off-line pre-push information into the first file;
if not, judging whether the request type is an offline push information pause request or not, and if so, calculating a second request data length of the offline push information pause request; continuously acquiring response data returned by the target server until the offline pause push information request is not acquired any more, and counting all the acquired response data to obtain second response data; creating a second file, and inputting a first preset field of the offline pause pushing information into the second file;
otherwise, when the request type is not an off-line pre-push information request and an off-line pause push information request, judging whether the request type is an off-line startup diagram push information request, and if the request type is the off-line startup diagram push information request, calculating a third request data length of the off-line startup diagram push information request; continuously acquiring response data returned by the target server until the offline startup diagram pushing information request is not acquired any more, and counting all the acquired response data to obtain third response data; and inputting a first preset field of the off-line startup picture pushing information into the second file.
Further, the method further comprises:
when the request type is a non-offline information pushing request, judging whether a first preset field recorded in the first file contains a hypertext transfer protocol (HTTP) address of the information pushing request, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
when the response data is a first preset threshold value, creating a third file;
and when the response data is a second preset threshold value, creating a fourth file, and inputting a second preset field of the information pushing request into the fourth file.
Further, the method further comprises:
and when the request type is a non-offline information pushing request and the first preset field recorded in the first file does not contain the HTTP address, judging whether the first preset field of the third file contains the HTTP address or not, and if so, recording the second preset field of the information pushing request into the fourth file.
Further, the method further comprises:
when the request type is a non-offline information pushing request, and a first preset field recorded in the first file does not contain the HTTP address and a first preset field of the third file does not contain the HTTP address, judging whether a first preset field recorded in the second file contains the HTTP address or not, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
and when the response data is the second preset threshold, creating a fifth file, and inputting a second preset field of the push information request into the fifth file.
Further, on the basis of the above embodiment, step 103 includes:
respectively counting the lengths of the first return data, the second return data and the third return data;
respectively counting the data sizes of the fourth file and the fifth file;
and calculating the sum of the first request data length, the second request data length, the third request data length, the first return data length, the second return data length, the third return data length, the data size of the fourth file and the data size of the fifth file to obtain the flow size.
Fig. 4 is a schematic flow chart of a fourth embodiment of the traffic statistic method provided in the present invention, as shown in fig. 4, the method includes the following steps:
(1) any request sent by a client is intercepted, the intercepted request information is analyzed and processed, and the ip address of a target server is obtained
(2) Creating socket to connect to target server, sending intercepted request to target server
(3) And (3) judging whether the request is a request for pushing information before off-line while executing the step (2), and if so, calculating the data length of the request for pushing information before off-line. If not, judging whether the request is the request of offline pause push information, and if so, calculating the data length of the request of offline pause push information. If not, judging whether the request is the request of pushing the information by the off-line startup graph, and if so, calculating the data length of the request of pushing the information by the off-line startup graph.
(4) And (3) after catching the information pushing request before offline, firstly, establishing an object (such as a flag) as an identifier with a value of 0, then establishing a cycle, and continuously waiting for the information pushing request and then returning data. The value of flag is set to 1 if data is returned and all data returned on a loop is given to the global variable self.
(5) And (4) after the execution of the step (4) is finished and the loop is skipped, if the value of flag is 1, calculating the number of the returned offline push information, creating RSvideo _ txt and monitorlist _ txt under the root directory of the flow measurement test tool, traversing the RS field value in each offline push information data, and writing the value into RSvideo _ txt. Traversing SUS, SU and SUE field values in each piece of before-offline push information data, and recording the values of the three fields into monitorelist.
(6) Calculating the size of a global variable self after the data is returned by the information pushing request before the offline.
(7) And (3) if the request is judged to be a non-offline information pushing request when the step (3) is executed, judging whether the field value of the RS stored in RSvideo _ txt contains the http address of the request, if so, analyzing the returned data of the request, if the response of the returned data is 302, finding the field value of the location, creating a video _ txt file, and writing the value into the video _ txt file. If the returned data response is 200, creating RSvideo off low.txt, finding a content-length field, and writing the value of the field into RSvideo off low.txt.
(8) And (3) if the request is judged to be neither an offline push information request nor contained in the rsvideo content.
(9) And (3) after the offline information pushing pause request is caught, firstly, establishing an object (such as a flag) as an identifier, wherein the value is 0, then establishing a loop, and continuously waiting for the information pushing request and then returning data. Pause is given to the value of flag if data is returned and all data returned during the loop is given to the global variable self.
(10) And (9) after the execution of the step (9) is finished and the loop is skipped, if the value of the flag is 1, calculating the number of the returned offline pause push information, creating RSpiclistat.txt under the root directory of the flow test tool, traversing the RS field value in each offline pause push information data, writing the value into RSpiclistat.txt, traversing the SUS field value in each offline pause push information data, and recording the field value into monitorelist.txt.
(11) Calculating the size of a global variable self.
(12) And (3) if the request is judged to be a non-offline information pushing request when the step (3) is executed, judging whether the HTTP address of the request is contained in the RS field value stored in the RSpiclistat.
(13) And (3) after the offline startup graph push information request is captured, firstly, creating an object (such as a flag) as an identifier, wherein the value is 0, then establishing a cycle, and continuously waiting for the push information request and then returning data. Set the value of flag to 1 if data is returned and assign all data returned in the loop to the global variable self.
(14) And (13) after the execution of the step (13) is finished and the loop is skipped, if the value of the flag is 1, calculating the number of the off-line startup graph push information returned this time, traversing the RS field value in each off-line startup graph push information data, writing the value into RSpiclistat.
(15) Calculating the size of a global variable self.
Fig. 5 is a schematic structural diagram of a first embodiment of a flow rate statistic device provided in the present invention, and as shown in fig. 5, the device includes:
an obtaining module 11, configured to obtain a push information request sent by a target device client, where the push information request includes: the address of the target server and the request type;
the obtaining module 11 is further configured to obtain response data returned by the target server according to the push information request;
and the counting module 12 is configured to count a traffic according to the push information request and the response data.
Further, the obtaining module 11 is specifically configured to:
acquiring a network protocol IP address of the terminal equipment and binding the target equipment;
and starting a monitoring program, and monitoring the push information request sent by the client on the target equipment.
Further, the obtaining module 11 is specifically configured to:
acquiring the IP address of the target server according to the push information request;
connecting the target server and sending the push information request to the target server;
and acquiring response data returned by the target server aiming at different request types according to the request type of the information pushing request.
Further, the obtaining module 11 is specifically configured to:
judging whether the request type is an offline pre-information pushing request or not, and if the request type is the offline pre-information pushing request, calculating a first request data length of the offline pre-information pushing request; continuously acquiring response data returned by the target server until the push information request before offline is not acquired any more, and counting all the acquired response data to obtain first response data; creating a first file, and inputting a first preset field of the off-line pre-push information into the first file;
if not, judging whether the request type is an offline push information pause request or not, and if so, calculating a second request data length of the offline push information pause request; continuously acquiring response data returned by the target server until the offline pause push information request is not acquired any more, and counting all the acquired response data to obtain second response data; creating a second file, and inputting a first preset field of the offline pause pushing information into the second file;
otherwise, when the request type is not an off-line pre-push information request and an off-line pause push information request, judging whether the request type is an off-line startup diagram push information request, and if the request type is the off-line startup diagram push information request, calculating a third request data length of the off-line startup diagram push information request; continuously acquiring response data returned by the target server until the offline startup diagram pushing information request is not acquired any more, and counting all the acquired response data to obtain third response data; and inputting a first preset field of the off-line startup picture pushing information into the second file.
Further, the obtaining module 11 is further configured to:
when the request type is a non-offline information pushing request, judging whether a first preset field recorded in the first file contains a hypertext transfer protocol (HTTP) address of the information pushing request, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
when the response data is a first preset threshold value, creating a third file;
and when the response data is a second preset threshold value, creating a fourth file, and inputting a second preset field of the information pushing request into the fourth file.
Further, the obtaining module 11 is further configured to:
and when the request type is a non-offline information pushing request and the first preset field recorded in the first file does not contain the HTTP address, judging whether the first preset field of the third file contains the HTTP address or not, and if so, recording the second preset field of the information pushing request into the fourth file.
Further, the obtaining module 11 is further configured to:
when the request type is a non-offline information pushing request, and a first preset field recorded in the first file does not contain the HTTP address and a first preset field of the third file does not contain the HTTP address, judging whether a first preset field recorded in the second file contains the HTTP address or not, and if the first preset field contains the HTTP address, acquiring and analyzing response data returned by the target server;
and when the response data is the second preset threshold, creating a fifth file, and inputting a second preset field of the push information request into the fifth file.
Further, the statistic module 12 is configured to:
respectively counting the lengths of the first return data, the second return data and the third return data;
respectively counting the data sizes of the fourth file and the fifth file;
and calculating the sum of the first request data length, the second request data length, the third request data length, the first return data length, the second return data length, the third return data length, the data size of the fourth file and the data size of the fifth file to obtain the flow size.
The embodiment of the invention also provides a flow statistic system, which comprises a client, a server and the flow statistic device, wherein the client is used for sending a push information request to the server, and the server is used for returning response data according to the push information request.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention.