Background
The virtual machine traffic collection refers to collecting virtual machine traffic data, and generally obtains data such as an uplink traffic real-time speed, a downlink traffic real-time speed, and a total traffic based on elements such as an Internet Protocol (IP), a destination IP, a source port, a destination port, and a Protocol number interconnected between source networks.
In a data center, network traffic is generally divided into two types, one is interactive traffic between external users of the data center and internal servers, and such traffic is called north-south traffic or longitudinal traffic; the other is interactive traffic between servers inside the data center, which is also called east-west traffic or lateral traffic, wherein the east-west traffic more refers to traffic inside the cloud computing system, that is, traffic communicated between virtual machines in the cloud. With the advent of cloud computing, services such as searching, parallel computing and the like are more and more, and in order to support rich services, a cluster system formed by a large number of servers is required to complete work cooperatively, so that traffic between the servers becomes very large, that is, east-west traffic is very large.
The east-west flow has the characteristics of large flow, wide distribution and the like, and the requirements on flow acquisition, system analysis, network performance and the like are very high, so that the east-west flow is difficult to monitor, wherein the east-west flow acquisition is a necessary link for realizing the east-west flow monitoring.
The existing east-west flow collection technology generally utilizes a sampling module to collect network data, copies one part of the network data and sends the copied part of the network data to the network collection module, when the network flow is large (namely, the network data is large), the consumption of Central Processing Unit (CPU) resources is very large, and when the sampling module performs sampling statistics on the network data, if the sampling frequency is large, the CPU resource consumption is large, and if the sampling frequency is too small, the flow statistical error is large.
Content of application
In view of this, an object of the embodiments of the present application is to provide a method and an apparatus for acquiring a virtual machine traffic, an electronic device, and a storage medium, so as to reduce CPU resource consumption in a traffic acquisition process on the basis of ensuring accuracy of a traffic acquisition statistical result.
In a first aspect, an embodiment of the present application provides a method for acquiring virtual machine traffic, where the method includes: a traffic collection agent thread of a computing node acquires port configuration information of a virtual machine representing whether traffic collection is needed or not in the computing node; the flow acquisition agent thread determines a port of the virtual machine needing flow acquisition according to the configuration information; and the flow acquisition agent thread controls a packet capturing thread to perform flow packet capturing on the port of the virtual machine needing flow acquisition, so that the packet capturing thread obtains and sends flow information containing the flow size to a database for storage.
In the implementation process, the flow acquisition agent thread is used for controlling the packet capturing thread to perform flow packet capturing on a port of a virtual machine which needs flow acquisition in a computing node, the packet capturing thread directly acquires flow data output by the port of the virtual machine to obtain flow information containing flow, the accuracy of a flow acquisition statistical result is ensured, and the flow information containing flow is obtained without copying the flow data, so that compared with the prior art, the CPU resource consumption is greatly reduced, and when the port of the virtual machine does not output data flow data, the packet capturing thread consumes zero CPU resources.
Based on the first aspect, in a possible design, the step of controlling, by the traffic collection agent thread, a packet capturing thread to perform traffic capturing on the port of the virtual machine requiring traffic collection includes: the agent thread configures one packet capturing thread for each port of the virtual machine needing flow acquisition; and the agent thread controls each packet capturing thread to respectively perform flow packet capturing on the corresponding port of the virtual machine.
In the implementation process, a packet capturing thread is configured for each virtual machine port needing flow acquisition to capture packets, so that the workload of each packet capturing thread can be reduced, the working state of each packet capturing thread can be effectively and respectively controlled through the proxy thread, when the port of a certain virtual machine does not need to carry out flow acquisition, the corresponding packet capturing thread can be timely controlled to stop flow acquisition, and when the certain packet capturing thread cannot normally run, the flow acquisition of other packet capturing threads on the port of the corresponding virtual machine cannot be influenced.
Based on the first aspect, in a possible design, the controlling, by the traffic collection agent thread, a packet capturing thread to perform traffic capturing on a port of the virtual machine that needs traffic collection, so that the packet capturing thread obtains and sends traffic information including traffic size to a database for storage includes: the agent thread configures a flow acquisition green thread for the port of the virtual machine needing flow acquisition; and the proxy thread controls the packet capturing thread to perform traffic packet capturing on the port of the virtual machine through the green thread, so that the green thread sends the traffic information obtained from the packet capturing thread to the database for storage.
In the implementation process, the agent thread configures a traffic acquisition green thread for the port of the virtual machine requiring traffic acquisition, controls the packet capturing thread to perform traffic packet capturing on the port of the virtual machine through the green thread, and controls the working state of the packet capturing thread through the green thread when the agent thread cannot normally run so as to ensure normal traffic acquisition.
Based on the first aspect, in a possible design, the controlling, by the traffic collection agent thread, a packet capturing thread to perform traffic capturing on a port of the virtual machine that needs traffic collection, so that the packet capturing thread obtains and sends traffic information including traffic size to a database for storage includes: the agent thread configures a traffic collection green thread for each port of the virtual machine needing traffic collection; and the agent thread controls the corresponding packet capturing thread to perform traffic packet capturing on the port of the virtual machine through each green thread, so that each green thread sends first traffic information obtained from the corresponding packet capturing thread to the database for storage.
In the implementation process, a flow acquisition green thread is configured for each port of the virtual machine needing flow acquisition, each green thread controls the corresponding packet capturing thread to carry out flow packet capturing on the port of the virtual machine, and because each green acquisition thread operates independently, the operation state of the packet capturing threads controlled by other green threads cannot be influenced when any one flow acquisition green thread cannot operate normally, meanwhile, the workload of each green thread is reduced, and the control on the working state of each packet capturing thread is facilitated.
Based on the first aspect, in a possible design, the step of controlling a packet capturing thread to perform traffic packet capturing on the port of the virtual machine requiring traffic acquisition includes: and controlling the packet capturing thread to perform real-time flow packet capturing on the port of the virtual machine to be acquired.
In the implementation process, the packet capturing thread is controlled to capture the real-time traffic of the port of the virtual machine to be acquired, so that the accuracy of the traffic acquisition statistical result is improved.
Based on the first aspect, in one possible design, before a traffic collection agent thread of a compute node acquires port configuration information of a virtual machine in the compute node, the virtual machine characterizing whether traffic collection is required, the method further includes: and the agent thread synchronizes port configuration information of the virtual machine representing whether flow collection is needed or not in the computing node in real time.
In the implementation process, the agent thread synchronizes port configuration information of the virtual machine representing whether the flow acquisition is needed in the computing node in real time, so that when the configuration information of the port of the virtual machine changes, the agent thread can control the packet capturing thread to perform flow acquisition on the port of the virtual machine which needs to perform flow acquisition at the current moment according to the latest configuration information.
In a second aspect, an embodiment of the present application provides a virtual machine traffic collection method, which is applied to a compute node, and the method includes: the flow collection agent thread of the computing node obtains port configuration information of a virtual machine which represents whether flow collection is needed or not in the computing node; the agent thread determines a port of the virtual machine needing flow collection according to the configuration information; the agent thread configures a traffic collection green thread for each port of the virtual machine needing traffic collection; for each green thread, the green thread controls a packet capturing thread to perform traffic packet capturing on a corresponding port of the virtual machine to obtain second traffic information containing traffic; and the traffic collection green thread also sends the second traffic information to a database for storage.
In the implementation process, the agent thread configures a flow acquisition green thread for each port of the virtual machine needing flow acquisition according to configuration information, each green thread controls the corresponding packet capturing thread to capture the flow of the port of the virtual machine, the packet capturing thread directly acquires flow data output by the port of the virtual machine to obtain flow information containing the flow, the accuracy of the flow acquisition statistical result is ensured, and the flow information containing the flow is obtained without copying the flow data, so that compared with the prior art, the CPU resource consumption is greatly reduced, meanwhile, because each green acquisition thread operates independently, the operation state of the packet capturing threads controlled by other green threads cannot be influenced when any one flow acquisition green thread cannot operate normally, and meanwhile, the workload of each green thread is also reduced, the control of the working state of each packet capturing thread is facilitated, wherein the life cycle of the packet capturing thread is managed by the traffic collection green thread, traffic information output by the packet capturing thread is forwarded to the database to be stored, and the consumption of the traffic collection green thread on a CPU is very low.
In a third aspect, an embodiment of the present application provides a virtual machine traffic collection device, where the device includes: the first configuration information acquisition module is used for a traffic acquisition agent thread of a computing node to acquire port configuration information of a virtual machine which represents whether traffic acquisition is needed or not in the computing node; the first port determining module is used for determining a port of the virtual machine needing flow acquisition by the agent thread according to the configuration information; and the first packet capturing module is used for controlling the packet capturing thread to perform traffic packet capturing on a port of the virtual machine which needs traffic acquisition by the agent thread so as to enable the packet capturing thread to obtain and send traffic information containing traffic to a database for storage.
Based on the third aspect, in a possible design, the first packet capturing module is further configured to configure, by the agent thread, one packet capturing thread for each port of the virtual machine that needs traffic collection; and the agent thread controls each packet capturing thread to respectively perform flow packet capturing on the corresponding port of the virtual machine.
Based on the third aspect, in a possible design, the first packet capturing module is further configured to configure, by the agent thread, a traffic collection green thread for the port of the virtual machine that needs traffic collection; and the proxy thread controls the packet capturing thread to perform traffic packet capturing on the port of the virtual machine through the green thread, so that the green thread sends the traffic information obtained from the packet capturing thread to the database for storage.
Based on the third aspect, in a possible design, the first packet capturing module is further configured to configure, by the agent thread, a traffic collection green thread for each port of the virtual machine that needs traffic collection; and the agent thread controls the corresponding packet capturing thread to perform traffic packet capturing on the port of the virtual machine through each green thread, so that each green thread sends first traffic information containing traffic size obtained from the corresponding packet capturing thread to the database for storage.
Based on the third aspect, in a possible design, the first packet capturing module is further configured to control the packet capturing thread to perform real-time traffic packet capturing on the port of the virtual machine that needs to be acquired.
In a possible design based on the third aspect, the apparatus further includes: and the configuration information synchronization module is used for synchronizing the port configuration information of the virtual machine which represents whether the flow acquisition is needed or not in the computing node in real time by the agent thread.
In a fourth aspect, an embodiment of the present application provides a virtual machine traffic collection apparatus, which is applied to a compute node, and the apparatus includes: a second configuration information obtaining module, configured to obtain, by a traffic collection agent thread of the computing node, port configuration information of a virtual machine representing whether traffic collection is required in the computing node; a second port determining module, configured to determine, by the agent thread, a port of the virtual machine that needs traffic acquisition according to the configuration information; the thread configuration module is used for configuring a traffic collection green thread for each port of the virtual machine needing traffic collection by the agent thread; the second packet capturing module is used for controlling the packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine aiming at each green thread to obtain second traffic information; and the storage module is used for the traffic collection green thread and sending the second traffic information to a database for storage.
In a fifth aspect, an embodiment of the present application provides an electronic device, including a processor and a memory connected to the processor, where a computer program is stored in the memory, and when the computer program is executed by the processor, the electronic device is caused to perform the method of the first aspect and the second aspect.
In a sixth aspect, embodiments of the present application provide a storage medium, in which a computer program is stored, and when the computer program runs on a computer, the computer is caused to execute the method of the first aspect and the second aspect.
Additional features and advantages of the present application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the embodiments of the present application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Detailed Description
The technical solution in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
For convenience of understanding, the application scenarios of the embodiments of the present application are briefly described below:
in a first application scenario, an embodiment of the present application provides a virtual cloud platform, where the virtual cloud platform includes: the control node can be deployed on a server deployed by any one of the at least one computing node, the control node can also be deployed on a server different from the server deployed by the at least one computing node, the control node and the at least one computing node are in communication connection, at least one virtual machine is deployed in the at least one computing node, the virtual machines in the virtual cloud platform are in mutual communication, and the control node synchronizes configuration information of ports of the virtual machines in the at least one computing node in real time; wherein each virtual machine includes at least one port.
A second application scenario, wherein the virtual cloud platform includes: the control node and the network node may be deployed on a server to which any one of the at least one computing node belongs, the control node and the network node may also be deployed on a server different from the server to which the at least one computing node is deployed, the at least one computing node, the network node and the control node are in communication connection with each other, the network node is in communication connection with the at least one computing node, at least one virtual machine is deployed in the at least one computing node, a virtual router is deployed on the network node, and the virtual machines in the virtual cloud platform and the virtual machines and the virtual router are in communication with each other. The control node synchronizes the configuration information of the ports of the virtual machines in the at least one computing node in real time; wherein each virtual machine includes at least one port.
In a third application scenario, the control node is a server deployed outside the virtual platform, the control node is in communication connection with a computing node in the virtual cloud platform, and the control node synchronizes configuration information of a port of a virtual machine in the virtual platform in real time.
Referring to fig. 1, an embodiment of the present application provides a flowchart of a virtual machine traffic collection method, which is applied to any one of the computing nodes in any one of the application scenarios, where the method includes: s100 and S200.
S100: and a traffic collection agent thread of the computing node acquires port configuration information of the virtual machine representing whether traffic collection is needed or not in the computing node.
S200: and the flow acquisition agent thread determines the port of the virtual machine needing flow acquisition according to the configuration information.
S300: and the flow acquisition agent thread controls a packet capturing thread to perform flow packet capturing on the port of the virtual machine needing flow acquisition, so that the packet capturing thread obtains and sends flow information containing the flow size to a database for storage.
The above method is described in detail below:
the traffic collection of the virtual machine in the compute node means to count traffic data of a port of the virtual machine that needs traffic collection in the compute node, however, when configuration information of the port of the virtual machine in the compute node changes, the port of the virtual machine that needs traffic collection may change, and therefore, as an embodiment, before S100, the method further includes: and the agent thread synchronizes port configuration information of the virtual machine representing whether flow collection is needed or not in the computing node in real time.
Wherein the port configuration information includes: the virtual machine comprises a first identifier for representing the identity of the virtual machine, a name of a computing node where the port is located, an identifier for representing whether traffic collection needs to be performed on the port of the virtual machine, an identifier for representing whether a network card is the network card of the virtual machine, an Internet Protocol (IP) address and a port number of the port of the virtual machine, and a Media Access Control (MAC) address (also called a physical address).
When the interactive traffic between the computing nodes in the virtual cloud platform needs to be collected, it can be understood that when the interactive traffic between the virtual machines between the computing nodes in the virtual cloud platform needs to be collected, the computing node a starts a traffic collection agent thread a11, where the agent thread is located in the computing node a and outside the virtual machines in the computing node a, the agent thread a11 sends configuration information for characterizing the ports of the virtual machines in the computing node a where the agent thread a11 needs to be obtained to the control node, the control node sends the configuration information of the ports of the virtual machines in the computing node a to the agent thread a11, and when the configuration information of the ports of the virtual machines in the computing node a changes, the control node sends the latest port configuration information of the virtual machines in the computing node a to the agent thread, so that the agent thread a11 synchronizes the configuration information of the ports of the virtual machines in compute node a in real time.
In one embodiment, when a compute node B is a control node and traffic collection needs to be performed on a port of a virtual machine deployed in the compute node B, the compute node B starts a traffic collection agent thread B1, and the traffic collection agent thread B1 synchronizes configuration information of the virtual machine in the compute node B in real time.
S100: and a traffic collection agent thread of the computing node acquires port configuration information of the virtual machine representing whether traffic collection is needed or not in the computing node.
After the traffic collection agent thread synchronizes, in real time, port configuration information of a virtual machine representing whether traffic collection is needed in the computing node, the port configuration information of the virtual machine in the computing node, which is acquired by the agent thread, is latest port configuration information, and when the port configuration information of the virtual machine in the computing node changes, the port configuration information of the virtual machine, which is acquired by the agent thread, also changes, for example, when a port of the virtual machine in the computing node is created or deleted, the port configuration information of the virtual machine in the computing node also changes correspondingly. For example, when the identifier indicating whether traffic collection is required for a port of the virtual machine changes, the configuration information of the port changes.
As an embodiment, a traffic collection agent thread of a compute node may obtain port configuration information of a virtual machine in the compute node at a current time only when the traffic collection thread is started.
S200: and the flow acquisition agent thread determines the port of the virtual machine needing flow acquisition according to the configuration information.
The port configuration information of each virtual machine comprises a port number and an identifier for representing whether the port of the virtual machine needs to be subjected to traffic collection, so that the port of the virtual machine needing traffic collection is determined according to the port configuration information of each virtual machine.
S300: and the flow acquisition agent thread controls a packet capturing thread to perform flow packet capturing on the port of the virtual machine needing flow acquisition, so that the packet capturing thread acquires and sends flow information to a database for storage.
When the ports of the virtual machines requiring traffic acquisition are determined, the number of packet capturing threads configured for the ports of the virtual machines requiring traffic acquisition is at least one, the number of packet capturing threads may be one, two, three, and the like, and the number of packet capturing threads may also be set according to the number of the ports requiring traffic acquisition, for example, referring to fig. 2, when the number of the ports of the virtual machines requiring traffic acquisition in the compute node is three, and only one packet capturing thread in the compute node is provided, the packet capturing thread is responsible for performing traffic capture on all the ports requiring traffic acquisition in the compute node.
Referring to fig. 3, when the number of ports of the virtual machine requiring traffic acquisition in the compute node is three, and there are two packet capturing threads in the compute node, one of the packet capturing threads is only responsible for performing traffic capturing on one port requiring traffic acquisition, and the other packet capturing thread is responsible for performing traffic capturing on the remaining two ports requiring traffic acquisition. The remaining two ports requiring traffic collection may be virtual machine ports on the same virtual machine, or virtual machine ports on two different virtual machines.
The method comprises the steps that flow packet capturing is carried out on flow data of a port needing flow acquisition in a packet capturing thread, flow information representing the size of flow can be obtained without copying the flow data of the port, and the packet capturing thread sends the flow information to a database for storage after the flow information is obtained by the packet capturing thread, wherein the database can be a time sequence database or other types of databases. The traffic information may be an uplink traffic real-time speed and/or a downlink traffic real-time speed, which are composed of a source IP, a destination IP, a source port, a destination port, and a protocol number 5 tuple, and/or total traffic data in a certain time period. The traffic information may also be an uplink traffic speed and/or a downlink traffic speed in a certain time period, which is composed of a source IP, a source port, and a protocol number 3 tuple, and/or total traffic data in a certain time period. The content included in the flow information is set according to the user requirement. For example, the format of the traffic information stored in the database is: 2019.7.20 flow information from 8 am 10 to 2019.7.20 am 8 am 20 is: the source IP is SS1, the destination IP is SS2, the source port is KK1, the destination port is KK2, the protocol number is WW1, the uplink flow rate is XX bit/s, the downlink flow rate is YY bit/s, and the total flow data is ZZ bit.
The packet capturing thread directly acquires the flow data output by the port of the virtual machine to obtain the flow information containing the flow, so that the accuracy of the flow acquisition statistical result is ensured, and the flow information containing the flow is obtained without copying the flow data.
In order to improve the accuracy of the statistical result of traffic collection, as an implementation manner, the step of controlling a packet capturing thread to perform traffic capture on a port of a virtual machine requiring traffic collection includes: and controlling the packet capturing thread to perform real-time flow packet capturing on the port of the virtual machine to be acquired. It can be understood that the packet capturing thread is controlled to continuously perform traffic collection on the ports of the virtual machines needing to be collected.
In order to reduce the workload of the packet capturing thread, as an implementation manner, the step of controlling the packet capturing thread to perform traffic capturing on a port of a virtual machine requiring traffic acquisition includes: and controlling the packet capturing thread to perform flow packet capturing on the port of the virtual machine to be acquired according to a preset time interval, wherein the longer the preset time interval is, the smaller the workload of the packet capturing thread is, but the accuracy of the flow acquisition statistical result is relatively reduced, so that the duration of the preset time interval is reasonably set to reduce the workload of the packet capturing thread on the basis of ensuring the accuracy of the flow acquisition statistical result.
In order to further reduce the workload of the packet capturing thread, please refer to fig. 3, as an embodiment, the step of controlling the packet capturing thread to perform traffic capturing on the port of the virtual machine requiring traffic capturing by the traffic capturing agent thread includes: AA and BB.
AA: and the agent thread configures one packet capturing thread for each port of the virtual machine needing flow acquisition.
When determining the ports of the virtual machines needing traffic acquisition, configuring a packet capturing thread for each port of the virtual machine needing traffic acquisition respectively to obtain the corresponding relation between the ports and the packet capturing threads.
BB: and the agent thread controls each packet capturing thread to respectively perform flow packet capturing on the corresponding port of the virtual machine.
After the agent thread configures a packet capturing thread for a port of a virtual machine requiring traffic collection, the agent thread controls each packet capturing thread to respectively perform traffic capturing on the corresponding port of the virtual machine. After the agent thread configures packet capturing threads for all ports of the virtual machines needing traffic acquisition in the compute node, the agent thread controls each packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine according to a predetermined corresponding relationship between the packet capturing threads and the ports.
The proxy thread may directly control the packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine after configuring the packet capturing thread for the port of one virtual machine in the compute node, which needs traffic acquisition, and then, the compute node directly controls the packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine after configuring the packet capturing thread for the port of the next virtual machine, which needs traffic acquisition, until all the ports of the virtual machines in the compute node, which need traffic acquisition, are configured with the packet capturing thread to perform traffic packet capturing.
The packet capturing thread is configured for each virtual machine port needing flow acquisition, so that the workload of each packet capturing thread can be reduced, the working state of each packet capturing thread can be effectively and respectively controlled through the agent thread, when the port of a certain virtual machine does not need flow acquisition, the corresponding packet capturing thread can be timely controlled to stop flow acquisition, and when the certain packet capturing thread cannot normally operate, the flow acquisition of other packet capturing threads to the port of the corresponding virtual machine cannot be influenced.
In order to ensure normal traffic collection when the agent thread cannot run normally, referring to fig. 4, as an embodiment, S300 includes the steps of: CC and DD.
CC: and the agent thread configures a flow acquisition green thread for the port of the virtual machine needing flow acquisition.
After the agent thread determines the port of the virtual machine requiring traffic acquisition, the agent thread configures a traffic acquisition green thread to control a packet capturing thread to perform traffic packet capturing on the port of the virtual machine requiring traffic acquisition.
When determining that the ports of the virtual machines requiring traffic acquisition exist, the number of the traffic acquisition green threads is at least one, the number of the green threads may be one, two, three, and the like, and the number of the green threads may also be set according to the number of the ports requiring traffic acquisition, for example, when the number of the ports of the virtual machines requiring traffic acquisition in the compute node is four, and only one packet capturing thread in the compute node exists, the green thread may be responsible for controlling the packet capturing thread to perform traffic packet capturing on all the ports requiring traffic acquisition in the compute node, when the number of the ports requiring traffic acquisition in the compute node is three, and two green threads in the compute node exist, one of the green threads is only responsible for controlling the packet capturing thread to perform traffic packet capturing on one port requiring traffic acquisition, and the other green thread is responsible for controlling the packet capturing thread to capture the traffic of the two rest ports needing traffic acquisition. Wherein, the packet capturing thread controlled by different green threads is different.
DD: and the proxy thread controls the packet capturing thread to perform traffic packet capturing on the port of the virtual machine through the green thread, so that the green thread sends the traffic information obtained from the packet capturing thread to the database for storage.
The green thread is used for controlling the working state of the packet capturing thread, and it can be understood that the green thread is used for controlling the life cycle of the packet capturing thread and sending the traffic information output by the packet capturing thread to the database for storage, so that the consumption of CPU resources only when the traffic is collected green is very low.
When the agent thread only configures a green acquisition thread and a packet capturing thread for ports of all virtual machines needing traffic acquisition in the computing node, the agent thread controls the green thread to be in a working state, the green acquisition thread controls the packet capturing thread to perform traffic packet capturing on the ports of all virtual machines needing traffic acquisition, the packet capturing thread obtains traffic information, the packet capturing thread sends the traffic information to the green thread, and the green thread sends the traffic information to a database for storage.
When the agent thread only configures one green acquisition thread and at least two packet capturing threads for all ports of the virtual machines needing traffic acquisition in the computing node, the green acquisition thread controls each packet capturing thread in the at least two packet capturing threads to respectively perform traffic packet capturing on the corresponding ports of the virtual machines needing traffic acquisition.
For example, the at least two packet grabbing threads comprise: the method comprises an A packet capturing thread and a B packet capturing thread, wherein the A packet capturing thread is responsible for capturing packets at a port A1 and a port A2, the B packet capturing thread is responsible for capturing packets at a port B1, the A packet capturing thread is controlled by the traffic collection green thread to respectively capture the traffic packets at the port A1 and the port A2, and the B packet capturing thread is controlled by the traffic collection green thread to capture the traffic packets at the port B1.
For example, the at least two packet grabbing threads comprise: the traffic collection method comprises an A packet capturing thread and a B packet capturing thread, wherein the A packet capturing thread is responsible for a port A1 and performs packet capturing, the B packet capturing thread is responsible for capturing a packet of a port B1, the A packet capturing thread is controlled by the traffic collection green thread to perform traffic capturing on the port A1, and the B packet capturing thread is controlled by the traffic collection green thread to perform traffic capturing on a port B1.
When the agent thread configures at least two green acquisition threads and at least two packet capturing threads for all ports of virtual machines needing traffic acquisition in the computing node, wherein the number of the packet capturing threads is greater than or equal to that of the green acquisition threads, and the at least two green acquisition threads respectively control the corresponding packet capturing threads to perform traffic packet capturing on the corresponding ports of the virtual machines needing traffic acquisition.
For example, the at least two green threads include: the system comprises an A green thread and a B green thread, wherein the at least two packet grabbing threads comprise: the method comprises an A packet capturing thread and a B packet capturing thread, wherein the A packet capturing thread is responsible for capturing packets by a port A1 and a port A2, the B packet capturing thread is responsible for capturing packets by a port B1, an A green thread controls the A packet capturing thread to respectively capture traffic packets by a port A1 and a port A2, and a B green thread controls the B packet capturing thread to capture traffic packets by a port B1.
To further reduce the workload of the green capture threads and facilitate the control of the green capture threads on the working state of each packet capturing thread, referring to fig. 5, as an embodiment, S300 includes the steps of: e and F.
E: and the agent thread configures a traffic collection green thread for each port of the virtual machine needing traffic collection.
After determining the ports of the virtual machines needing traffic acquisition according to the configuration information, the agent thread configures a traffic acquisition green thread for each port of the virtual machine needing traffic acquisition, and it can be understood that the number of the green threads is the same as the number of the ports of the virtual machines needing traffic acquisition, one green thread corresponds to one port of the virtual machine needing traffic acquisition, and then the corresponding relationship between the traffic acquisition green thread and the port can be obtained, wherein both the traffic acquisition green thread and the port have unique identifiers. For example, traffic collection green thread a corresponds to the a1 port and traffic collection green thread B corresponds to the B1 port.
F: and the agent thread controls the corresponding packet capturing thread to perform traffic packet capturing on the port of the virtual machine through each green thread, so that each green thread sends first traffic information containing traffic size obtained from the corresponding packet capturing thread to the database for storage.
The green threads and the packet capturing threads are the same in number, and one green thread controls one packet capturing thread to perform traffic packet capturing on a port of a virtual machine which needs traffic collection.
After the agent thread configures a green thread and a packet capturing thread for a port of a virtual machine requiring traffic collection, the agent thread controls the corresponding packet capturing thread to respectively capture traffic of the corresponding port of the virtual machine through each green thread. The proxy thread may configure a green thread and a packet capturing thread for each port of a virtual machine that needs traffic collection in a compute node, and then the proxy thread starts each green thread in the compute node at the same time to enable the green thread to be in a working state, so that each green thread controls a corresponding packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine according to a predetermined correspondence between the green thread and the port.
The method may further include the step that after the agent thread configures a green thread and a packet capturing thread for a port of one virtual machine in the compute node, the agent thread starts the green thread to directly control the packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine, and then, after the compute node configures a traffic acquiring thread and a packet capturing thread for a port of a next virtual machine requiring traffic acquisition, the traffic acquiring thread directly controls the packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine until all ports of the virtual machines requiring traffic acquisition in the compute node are configured with traffic acquiring threads and packet capturing threads to perform traffic packet capturing.
The port of the virtual machine which needs flow collection is provided with a flow collection green thread and a packet capturing thread, each of the green threads controls the corresponding packet capturing thread to carry out flow packet capturing on the port of the virtual machine, and because each green collection thread operates independently, the operating state of the packet capturing thread controlled by other green threads cannot be influenced when any flow collection green thread cannot operate normally.
Referring to fig. 6, another virtual machine traffic collection method provided in the embodiment of the present application is applied to a compute node, and the method includes the steps of: s400, S500, S600 and S700.
S400: and the traffic collection agent thread of the computing node acquires port configuration information of the virtual machine representing whether traffic collection is needed in the computing node.
S500: the agent thread determines a port of the virtual machine needing flow collection according to the configuration information;
s600: and the agent thread configures a traffic collection green thread for each port of the virtual machine needing traffic collection.
S700: and for each green thread, controlling a packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine by the green thread to obtain second traffic information containing traffic.
S800: and the traffic collection green thread also sends the second traffic information to a database for storage.
For details of the implementation process of this embodiment, please refer to the contents described in the embodiments shown in fig. 1 to fig. 5, which are not described herein again.
Referring to fig. 7, an embodiment of the present application provides a schematic structural diagram of a virtual machine traffic collection device, where the device includes:
a first configurationinformation obtaining module 410, configured to obtain, by a traffic collection agent thread of a compute node, port configuration information of a virtual machine that represents whether traffic collection is required in the compute node.
A firstport determining module 420, configured to determine, by the agent thread according to the configuration information, a port of the virtual machine that needs to acquire traffic.
The firstpacket capturing module 430 is configured to control a packet capturing thread to perform traffic capturing on a port of a virtual machine that needs traffic acquisition by the agent thread, so that the packet capturing thread obtains and sends traffic information including traffic size to a database for storage. As an implementation manner, the firstpacket capturing module 430 is further configured to configure, by the agent thread, one packet capturing thread for each port of the virtual machine that needs to acquire traffic; and the agent thread controls each packet capturing thread to respectively perform flow packet capturing on the corresponding port of the virtual machine.
As an embodiment, the firstpacket capturing module 430 is further configured to enable the agent thread to acquire a green thread for the port traffic of the virtual machine requiring traffic acquisition; and the proxy thread controls the packet capturing thread to perform traffic packet capturing on the port of the virtual machine through the green thread, so that the green thread sends the traffic information obtained from the packet capturing thread to the database for storage.
As an implementation manner, the firstpacket capturing module 430 is further configured to configure, by the agent thread, a traffic collection green thread for each port of the virtual machine that needs traffic collection; and the agent thread controls the corresponding packet capturing thread to perform traffic packet capturing on the port of the virtual machine through each green thread, so that each green thread sends first traffic information containing traffic size obtained from the corresponding packet capturing thread to the database for storage.
As an implementation manner, the firstpacket capturing module 430 is further configured to control the packet capturing thread to perform real-time traffic packet capturing on the port of the virtual machine that needs to be acquired.
As an embodiment, the apparatus further comprises: and the configuration information synchronization module is used for synchronizing the port configuration information of the virtual machine which represents whether the flow acquisition is needed or not in the computing node in real time by the agent thread.
For the process of implementing each function by each functional unit in this embodiment, please refer to the content described in the embodiments shown in fig. 1 to fig. 5, which is not described herein again.
Referring to fig. 8, an embodiment of the present application provides a schematic structural diagram of another virtual machine traffic collection apparatus, where the apparatus is applied to a compute node, and the apparatus includes:
a second configuration information obtaining module 510, where the traffic collection agent thread of the computing node obtains port configuration information of a virtual machine in the computing node, where the port configuration information represents whether traffic collection is needed.
A second port determining module 520, configured to determine, by the agent thread, a port of the virtual machine that needs to acquire traffic according to the configuration information.
A thread configuration module 530, configured to configure a traffic collection green thread for each port of the virtual machine that needs traffic collection by the agent thread.
And a second packet capturing module 540, configured to control, for each green thread, the packet capturing thread to perform traffic packet capturing on the corresponding port of the virtual machine, so as to obtain second traffic information.
And the storage module 550 is used for the traffic collection green thread to further send the second traffic information to the database for storage.
Please refer to the content described in the embodiment shown in fig. 6 for the process of implementing each function by each functional unit in this embodiment, which is not described herein again.
Referring to fig. 9, fig. 9 is a schematic structural diagram of anelectronic device 100 according to an embodiment of the present disclosure, where theelectronic device 100 may be a computing node or a control node, and theelectronic device 100 may be a Personal Computer (PC), a tablet PC, a smart phone, a Personal Digital Assistant (PDA), or the like.
Theelectronic device 100 may include:memory 102, processing 101, and a communication bus for enabling connection communication of these components.
TheMemory 102 is used to store configuration information of a port of a virtual machine, and various data such as a computer program instruction corresponding to the virtual machine traffic collection method and apparatus provided in this embodiment, where theMemory 102 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an erasable Read-Only Memory (EPROM), an electrically erasable Read-Only Memory (EEPROM), and the like.
Theprocessor 101 is configured to execute the steps of the virtual machine traffic collection method provided in the embodiment of the present application when reading and executing the computer program instructions stored in the memory.
Theprocessor 101 may be an integrated circuit chip having signal processing capability. TheProcessor 101 may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed.
In addition, a storage medium is provided in an embodiment of the present application, and a computer program is stored in the storage medium, and when the computer program runs on a computer, the computer is caused to execute the method provided in any embodiment of the present application.
To sum up, in the virtual machine traffic collection method, apparatus, electronic device and storage medium provided in each embodiment of the present application, the traffic collection agent thread is used to control the packet capturing thread to perform traffic packet capturing on the port of the virtual machine that needs traffic collection in the compute node, the packet capturing thread directly collects traffic data output by the port of the virtual machine to obtain traffic information including traffic size, so as to ensure accuracy of a traffic collection statistical result, and the traffic data does not need to be copied to obtain the traffic information including traffic size.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based devices that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The above description is only a preferred embodiment of the present application and is not intended to limit the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.