Method and system for monitoring internal network of host machine

By obtaining and monitoring the topology diagram of the host's virtual machines and container network devices, the problem of internal traffic monitoring of the host is solved, clear statistics and instance traffic derivation of virtual machine and container network data are achieved, and monitoring and maintenance costs are reduced. .

CN118540238APending Publication Date: 2024-08-23BEIJING QINMU DATA TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410537282.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-30
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

The existing technology cannot effectively monitor the east-west traffic within the host, is troublesome to deploy and maintain, has poor adaptability, cannot monitor the entire traffic, and is difficult to distinguish the network traffic of each virtual machine or container.

Method used

By obtaining the information of all virtual machines and containers in the host, determine the network devices of the virtual machines and containers, establish network topology diagrams, monitor based on these diagrams, obtain the network transceiver status of the virtual machines and containers, and form monitoring data. There is no need to deploy a monitoring program on each virtual machine or container, and it does not rely on the data mirroring of the virtual switch or the SFlow, NetFlow, and OpenFlow functions.

Benefits of technology

It realizes clear statistics of network data statistics of all virtual machines and containers within the host, reduces monitoring and maintenance costs, has strong adaptability, can deduce the instance traffic of virtual machines and containers, and simplifies the monitoring process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118540238A
    Figure CN118540238A
Patent Text Reader

Abstract

The invention provides a host machine internal network monitoring method and system, and the method comprises the steps: determining a Tun network device corresponding to a virtual network card according to the information of a virtual machine, building a network topology relation graph of the virtual machine around the Tun network device, obtaining a veth device applied during the operation of each container according to the information of the container, and carrying out the monitoring of the internal network of the host machine. Establishing a network topological relation graph of the container around the veth device, and then monitoring the Tun device based on the network topological relation graph of the virtual machine to obtain the network transceiving condition of the virtual machine corresponding to the Tun device; the veth device is monitored based on the network topology relation graph of the container to obtain the network transceiving condition of the container corresponding to the veth device, so that the network transceiving condition of the virtual machine and the network transceiving condition of the container are packaged to form the host machine monitoring data, a monitoring program does not need to be deployed in each virtual machine and container, and the monitoring efficiency is improved. And the network data statistical information of all virtual machines and containers can be clearly counted without depending on the data mirror image of the virtual switch.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network communication technology, and more specifically, to a method for monitoring an internal network of a host machine. Background Art

[0002] The host machine is the most important part of virtualization technology. The main task of the host machine is to allocate resources and manage virtualization software. Currently, the most common virtualization technologies are virtual machines and containerization. Multiple virtual machines can run on a virtual machine host, and multiple containers can run on a container host.

[0003] Network communication occurs between virtual machines within a virtual machine host, and similarly, between containers within a container host, forming an internal network of the host. This internal network of the host is beyond the scope of traditional physical network traffic monitoring.

[0004] There are several technical means for monitoring the network traffic inside the host: 1) Identify the network traffic from the host through filtering and parsing techniques such as Vlan and ALC from the mirror data of the physical switch; 2) Deploy the network monitoring agent in the virtual machine or container / Pod; 3) Mirror the network data of the host to the network monitoring unit through the port mirroring function of the virtual switch; 4) Perform network monitoring through the virtual switch SFlow, NetFlow, OpenFlow and other functions. Among them, the first method directly uses the existing traditional network traffic monitoring method to only monitor the north-south traffic of the host, but cannot monitor the east-west traffic inside the host; the second method can accurately monitor each virtual machine or container / Pod inside the host, but the deployment and maintenance are very troublesome; the third method only needs to configure the port mirroring of the virtual switch, and does not need to change the monitored virtual machine, container / Pod, so the implementation is relatively simple, but it is suitable for virtual switches with port mirroring function; the fourth method basically realizes network monitoring through sampling data, which cannot monitor the entire traffic, and it is not easy to distinguish each individual virtual machine, container / Pod network, and also requires the virtual switch to have SFlow, NetFlow or OpenFlow functions.

[0005] Therefore, there is an urgent need for a monitoring method and system for the internal network of the host machine that does not require the deployment of a monitoring program in each virtual machine, container / Pod, and does not rely on the data mirroring, SFlow, NetFlow, OpenFlow and other functions of the virtual switch to clearly count the network data statistics of all virtual machines, Pod / docker containers, and is easy to deploy and maintain in the later stage and has strong adaptability. Summary of the invention

[0006] In view of the above problems, the purpose of the present invention is to provide a method and system for monitoring the internal network of a host machine, so as to solve the problems that the prior art cannot monitor the east-west traffic inside the host machine, is very troublesome to deploy and maintain, has poor adaptability, cannot monitor the entire traffic, and is difficult to distinguish between each individual virtual machine, container / Pod network.

[0007] The present invention provides a method for monitoring an internal network of a host machine, which includes:

[0008] Get information about all virtual machines and containers in the host;

[0009] Determine the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establish a network topology relationship diagram of the virtual machine inside the host machine around the Tun network device; and obtain the process and running status of each container according to the information of the container, confirm the network device information in the network namespace where each container is located based on the process and running status to lock the veth device used when each container is running, and establish a network topology relationship diagram of the container inside the host machine around the veth device;

[0010] Based on the network topology diagram of the virtual machine, the Tun device is monitored to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and based on the network topology diagram of the container, the veth device is monitored to obtain the network receiving and sending status of the container corresponding to the veth device;

[0011] The network receiving and sending status of the virtual machine and the network receiving and sending status of the container are encapsulated to form host machine monitoring data.

[0012] Preferably, the monitoring method is implemented by a remote monitoring program or a direct monitoring program; wherein,

[0013] The remote monitoring program runs on a preset remote monitoring platform;

[0014] The monitoring program runs on the host machine.

[0015] Preferably, the host monitoring data includes network data statistics of virtual machines and containers, and network traffic data of virtual machines and containers; wherein the network data statistics include internal network status and topological relationship data of the virtual machines and containers;

[0016] If the host machine monitoring data is network data statistics information of a virtual machine or a container, the monitoring method is implemented by a remote monitoring program, and the remote monitoring program uploads the network data statistics information to a monitoring platform connected to the remote monitoring program;

[0017] If the host monitoring data is network traffic data of a virtual machine or a container, the monitoring method is implemented by the listening program, and the monitoring method further includes:

[0018] The network traffic data is forwarded to a third-party data analysis and monitoring platform through direct connection or tunnel encapsulation.

[0019] Preferably, the process of obtaining information of all virtual machines in the host machine includes:

[0020] Obtain the names of all virtual machines in the host machine through a preset name acquisition command, and obtain the virtual network card information corresponding to each virtual machine name; wherein the virtual network card information includes the model, name, and Mac address of the virtual network card;

[0021] Querying the Tun device information corresponding to the virtual machine name through the virtual network card information, and using the Tun device information and virtual network card information corresponding to each virtual machine as the information of the respective virtual machine; wherein the Tun device information includes the name of the Tun device and the bridge information connected to the Tun device;

[0022] The process of obtaining information about all containers in the host includes:

[0023] The name list of all containers in the host is obtained through the preset list acquisition command, and all the name lists are used as container information.

[0024] Preferably, the steps of determining a virtual network card corresponding to each virtual machine and a Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establishing a network topology diagram of the virtual machine around the Tun network device include:

[0025] Extracting the virtual network card name from the information of the virtual machine, and retrieving the Tun device information associated with the virtual network card name to locate the Tun network device corresponding to each virtual machine in the host machine;

[0026] Based on the bridge information, a correspondence between each virtual machine, virtual network card name, Tun network device, bridge, and physical network card is established to form a network topology relationship diagram of the virtual machine.

[0027] Preferably, the steps of confirming the network device information in the network namespace where each container is located to lock the veth device used when each container is running, and establishing a network topology diagram of the container around the veth device include:

[0028] Obtain network device information of each container in the namespace through the instance process ID of the container;

[0029] Searching the network device information for a network device number of a veth device corresponding to the container in a network namespace;

[0030] Lock the target veth device based on the network device number of the veth device;

[0031] Obtain all bridges and virtual switches associated with the container and the target veth device on the host to form a network topology diagram of the container.

[0032] Preferably, if implemented by a remote monitoring program, the step of monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network transceiver status of the virtual machine corresponding to the Tun device includes:

[0033] Obtain the Tun device receiving and sending data statistics of each Tun device through a preset Tun device monitoring command; the Tun device receiving and sending data statistics include the number of bytes received / sent, the number of packets, and the number of error packets;

[0034] Confirm the correspondence between the virtual machine and the Tun device based on the network topology diagram of the virtual machine, and integrate the statistical information of the sent and received data of the Tun device to form the Tun device data statistical information;

[0035] Using the Tun device data statistics information as the network receiving and sending status of the virtual machine corresponding to the Tun device;

[0036] If implemented by a monitoring program, the step of monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device includes:

[0037] The Tun devices corresponding to the virtual machines are directly monitored by the monitoring program based on the network topology relationship of the virtual machines to obtain the real-time traffic data of each Tun device, and the actual traffic data is used as the network receiving and sending status of the corresponding virtual machines.

[0038] Preferably, the step of monitoring the veth device based on the network topology diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device includes:

[0039] Obtain the veth device sending and receiving data of each veth device through the preset veth device monitoring command;

[0040] Integrate all veth device received and sent data on the network topology diagram of the container to form veth device data statistics information;

[0041] The veth device data statistics information is used as the network receiving and sending status of the container corresponding to the veth device.

[0042] The present invention also provides a host internal network monitoring system, wherein the host internal network monitoring method as described above is implemented, including:

[0043] An information acquisition unit, used to acquire information of all virtual machines and containers in the host machine;

[0044] A device positioning unit is used to determine the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establish a network topology relationship diagram of the virtual machine inside the host machine around the Tun network device; and obtain the process and running status of each container according to the information of the container, confirm the network device information in the network namespace where each container is located according to the process and running status to lock the veth device used when each container is running, and establish a network topology relationship diagram of the container inside the host machine around the veth device;

[0045] A data monitoring unit, configured to monitor the Tun device based on the network topology relationship diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and to monitor the veth device based on the network topology relationship diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device;

[0046] The data encapsulation unit is used to encapsulate the network receiving and sending status of the virtual machine and the network receiving and sending status of the container to form host monitoring data.

[0047] Preferably, the information acquisition unit, the device positioning unit, the data monitoring unit, and the data encapsulation unit are integrated into a preset remote monitoring program or a monitoring program, wherein:

[0048] If integrated in the remote monitoring program, the remote monitoring program directly uploads the host machine monitoring data to a monitoring platform connected to the remote monitoring program;

[0049] If integrated into the monitoring program, it also includes a data forwarding unit; the data forwarding unit is used to forward the network traffic data to a third-party data analysis and monitoring platform through direct connection or tunnel encapsulation.

[0050] From the above technical solution, it can be seen that the monitoring method of the internal network of the host provided by the present invention first obtains the information of all virtual machines and containers in the host, and then determines the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establishes a network topology relationship diagram of the virtual machine around the Tun network device, obtains the process and running status of each container according to the information of the container, confirms the network device information in the network namespace where each container is located according to the process and running status to lock the veth device used when each container is running, and establishes a network topology relationship diagram of the container around the veth device, and then monitors the Tun device based on the network topology relationship diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; based on The network topology diagram of the container monitors the veth device to obtain the network receiving and sending status of the container corresponding to the veth device, thereby encapsulating the network receiving and sending status of the virtual machine and the container to form the host monitoring data. This method does not need to deploy a monitoring program on each virtual machine, container / Pod, nor does it rely on the data mirroring, SFlow, NetFlow, OpenFlow and other functions of the virtual switch to count the network data statistics of all virtual machines, Pod / docker containers (total number of packets received and sent, total number of bytes, number of error packets, number of lost packets), and the instance traffic (bps and pps received and sent) of each virtual machine, Pod / docker container can be derived through the scheduled query function of the monitoring program and the listening program. That is, only one command is needed to obtain the network data statistics of all virtual machines, containers / Pods in the host, greatly reducing the maintenance cost of monitoring the network data of virtual machines, Pod / docker containers in the host. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] By referring to the following description in conjunction with the accompanying drawings, and with a more comprehensive understanding of the present invention, other objects and results of the present invention will become more clear and easy to understand. In the accompanying drawings:

[0052] Figure 1 is a flow chart of a method for monitoring an internal network of a host machine according to an embodiment of the present invention;

[0053] Figure 2 A schematic structure of a connection between a host machine and a virtual machine in a method for monitoring an internal network of a host machine according to an embodiment of the present invention;

[0054] Figure 3 A schematic structure of a connection between a host and a container in a method for monitoring an internal network of a host according to an embodiment of the present invention;

[0055] Figure 4A schematic diagram of a flow chart of a remote monitoring program monitoring a virtual machine in a host machine in a method for monitoring an internal network of a host machine according to an embodiment of the present invention;

[0056] Figure 5 It is a schematic diagram of a flow chart of monitoring a virtual machine in a host machine by a monitoring program in a method for monitoring an internal network of a host machine according to an embodiment of the present invention;

[0057] Figure 6 It is a schematic diagram of a flow chart of monitoring a container in a host machine by a remote monitoring program in a method for monitoring an internal network of a host machine according to an embodiment of the present invention;

[0058] Figure 7 It is a schematic diagram of a flow chart of monitoring a container in a host machine by a listening program in a method for monitoring an internal network of a host machine according to an embodiment of the present invention;

[0059] Figure 8 This is a data diagram of the network receiving and sending status in the method for monitoring the internal network of a host machine according to an embodiment of the present invention;

[0060] Fig. 9 4 is a system block diagram of a monitoring system for an internal network of a host machine according to an embodiment of the present invention. DETAILED DESCRIPTION

[0061] At present, there are several main technical means to monitor the internal network of the host: 1) Distinguish the network traffic from the internal host through filtering and parsing techniques such as Vlan and ALC from the mirror data of the physical switch; 2) Deploy a network monitoring agent in a virtual machine or container / Pod; 3) Mirror the network data of the host to the network monitoring unit through the port mirroring function of the virtual switch; 4) Monitor the network through the virtual switch SFlow, NetFlow, OpenFlow and other functions. Among them, the first method directly uses the existing traditional network traffic monitoring method to only monitor the north-south traffic of the host, but cannot monitor the east-west traffic inside the host; the second method can accurately monitor each virtual machine or container / Pod inside the host, but the deployment and maintenance are very troublesome; the third method only needs to configure the port mirroring of the virtual switch, and does not need to change the monitored virtual machine, container / Pod, so the implementation is relatively simple, but it is suitable for virtual switches with port mirroring functions; the fourth method basically realizes network monitoring through sampling data, which cannot monitor the entire traffic, and it is not easy to distinguish each individual virtual machine, container / Pod network, and also requires the virtual switch to have SFlow, NetFlow or OpenFlow functions.

[0062] In view of the above problems, the present invention provides a method and system for monitoring an internal network of a host machine. The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0063] In order to illustrate the host internal network monitoring method and system provided by the present invention, Figure 1-Figure 9 The embodiments of the present invention are exemplarily indicated.

[0064] The following description of exemplary embodiments is merely illustrative in nature and is not intended to limit the present invention and its application or use. Technologies and devices known to ordinary technicians in the relevant field may not be discussed in detail, but in appropriate cases, the technologies and devices should be considered as part of the specification.

[0065] like Figure 2 As shown, the virtual machine host uses the Tun / Tap network interface device to achieve mutual communication between the virtual machine and the host. The Tun / Tap network interface device is mainly used to transfer data between the user space and the kernel space. The virtual network card in the virtual machine will be connected to a tun / tap network interface device on the host, and the other end of the Tun / Tap will be connected to a bridge or virtual switch on the host, so that the virtual machine can communicate with the outside world through the Tun / Tap. Taking the KVM host as an example, the virtual network card settings of the virtual machine must configure the virtual network card to a bridge or virtual switch. When the virtual machine starts running, the host system will generate a Tun network device on the bridge or virtual switch where the virtual network card is located to communicate with the virtual network card. In this way, the virtual machine can communicate with the outside world through the virtual network card.

[0066] like Figure 3 As shown in the figure, unlike virtual machines, containers do not have independent kernels. They are isolated from other containers and host resources (network, file system, etc.) through namespaces. Each container has an independent network namespace. Veth is a network device that appears in pairs. Containers use a pair of veth network devices to connect the container's network namespace with the host's network namespace. Taking the Docker container host as an example, whenever a Docker container instance is started, the host system will generate a veth interface on the docker0 bridge, and the Docker container instance will also have a veth type eth0 virtual network card paired with it to achieve communication functions.

[0067] That is, no matter it is a virtual machine or a container / Pod, there is a network device on the host machine that communicates network data with the virtual network card on the virtual machine or container / Pod, thereby realizing the network communication function between the virtual machine or container / Pod and the outside world. Therefore, the data sent and received through the virtual network card in the virtual machine or container / Pod will eventually pass through the Tun devices (tun / tap devices) and veth network devices on the corresponding host machine. As long as the corresponding relationship between the tun and tap devices on the virtual machine host and the virtual network cards in all virtual machines is sorted out, the effect of monitoring the network data of a certain virtual machine can be achieved by monitoring the tun / tap devices. Similarly, the effect of monitoring the network data of a certain container / Pod can be achieved by monitoring the veth network port device on the container host.

[0068] Specifically, Figure 1 As shown, the host internal network monitoring method provided by the present invention includes:

[0069] S110: Obtain information about all virtual machines and containers in the host machine;

[0070] S120: Determine the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establish a network topology relationship diagram of the virtual machine inside the host machine around the Tun network device; and obtain the process and running status of each container according to the information of the container, confirm the network device information in the network namespace where each container is located according to the process and running status to lock the veth device used when each container is running, and establish a network topology relationship diagram of the container inside the host machine around the veth device;

[0071] S130: Monitor the Tun device based on the network topology relationship diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and monitor the veth device based on the network topology relationship diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device.

[0072] S140: Encapsulate the network receiving and sending status of the virtual machine and the network receiving and sending status of the container to form host machine monitoring data.

[0073] like Figure 4-Figure 7As shown together, steps S110 to S140 in the monitoring method are implemented by a remote monitoring program or a listening program; wherein the remote monitoring program runs on a preset remote monitoring platform, and the listening program runs on the host machine. In this embodiment, the host machine monitoring data includes network data statistics of virtual machines and containers, as well as network traffic data of virtual machines and containers; wherein the network data statistics include internal network status and topological relationship data of the virtual machines and containers; if the host machine monitoring data is network data statistics of virtual machines and containers, then the monitoring method is implemented by the remote monitoring program, and the remote monitoring program uploads the network data statistics to the monitoring platform connected to the remote monitoring program; if the host machine monitoring data is network traffic data of virtual machines and containers, then the monitoring method is implemented by the listening program, and the monitoring method also includes: forwarding the network traffic data to a third-party data analysis monitoring platform through direct connection or tunnel encapsulation. If it is implemented by the remote monitoring program, then Figure 4 , Figure 6 As shown, the remote monitoring program directly uploads the host monitoring data to the monitoring platform connected to the remote monitoring program, and specifically, the remote monitoring program based on Python can be run; if it is implemented by the listening program, then Figure 5 , Figure 7 The method shown also includes: forwarding the host monitoring data out of the host through direct connection or tunnel encapsulation to enable the user to complete third-party monitoring, and the monitoring program can be based on libPcap. Therefore, there is no need to deploy a monitoring program in each virtual machine, container / Pod, and there is no need to rely on the data mirroring, SFlow, NetFlow, OpenFlow and other functions of the virtual switch to count the network data statistics of all virtual machines, Pod / docker containers (total number of packets sent and received, total number of bytes, number of error packets, number of lost packets), and the instance traffic (bps and pps sent and received) of each virtual machine, Pod / docker container can be derived through regular query. In the end, only one command is needed to obtain the network data statistics of all virtual machines, containers / Pods inside the host, which greatly simplifies the way to monitor the network data of virtual machines and Pod / docker containers inside the host.

[0074] In this embodiment, step S110 is a process of obtaining information of all virtual machines and containers in the host machine, wherein the process of obtaining information of all virtual machines in the host machine includes:

[0075] SA111: Obtain all virtual machine names in the host machine through a preset name acquisition command, and obtain virtual network card information corresponding to each virtual machine name; wherein the virtual network card information includes the model, name, and Mac address of the virtual network card;

[0076] SA112: querying the Tun device information corresponding to the virtual machine name through the virtual network card information, and using the Tun device information and virtual network card information corresponding to each virtual machine as the information of each virtual machine; wherein the Tun device information includes the name of the Tun device and the bridge information connected to the Tun device;

[0077] More specifically, you can use "virsh list --all" to obtain the names and states of all virtual machines in the KVM host, and get a list of all virtual machine names and states.

[0078] In a specific embodiment, during the specific implementation, the virtual network card information of the virtual machine can be obtained by using "virsh domiflist virtual machine name" as the name acquisition command, including: the model (Model) of the virtual network card, the Mac address (mac), the corresponding tun device (Interface) on the host machine, the virtual switch / bridge (Source) on the host machine where the tun device is located, etc., and the virtual network card information of the virtual machine in the running state and the virtual network card information of the virtual machine in the non-running state are obtained;

[0079] The process of obtaining information about all containers in the host includes:

[0080] SB111: Get the name list of all containers in the host through the preset list acquisition command, and use all the name lists as container information.

[0081] In a specific embodiment, "docker ps --format '{{.Names}}'" is used as a preset list acquisition command to obtain a name list of all Docker container instances on the host, and then obtain a name list of all Docker container instances in the current host.

[0082] Step S120 is a process of determining the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establishing a network topology relationship diagram of the virtual machine around the Tun network device; and a process of obtaining the process and running status of each container according to the information of the container, confirming the network device information in the network namespace where each container is located based on the process and running status to lock the veth device used when each container is running, and establishing a network topology relationship diagram of the container around the veth device.

[0083] The steps of determining a virtual network card corresponding to each virtual machine and a Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establishing a network topology diagram of the virtual machine around the Tun network device include:

[0084] SA121: extracting the virtual network card name from the information of the virtual machine, and retrieving the Tun device information associated with the virtual network card name to locate the Tun network device corresponding to each virtual machine in the host machine;

[0085] SA122: Based on the bridge information, a corresponding relationship between each virtual machine, virtual network card name, Tun network device, bridge, and physical network card is established to form a network topology diagram of the virtual machine;

[0086] In a specific embodiment, the virtual machine Winxp_VM has three virtual network cards. The mac address and Interface can be used to determine which tun device each network card of the virtual machine is connected to, and which virtual switch / bridge each tun device is on on the host machine; the virtual machine Winxp_2 has two virtual network cards. If the virtual machine is not running, it is determined that the host machine has not created a tun device, but it can be known which virtual switch / bridge the virtual machine is configured on.

[0087] More specifically, you can use "brctl show" to get all bridge names and the interface list on each bridge, and from it you can get all bridge names on the host and the interfaces on each bridge (including tun network devices, veth network devices, and physical network card devices). Use "ovs-vsctl list-br" to get all openvSwitch virtual switches. This command will list all openvSwitch virtual switch names on the host. For example, you can get: there is an openvSwitch virtual switch named ovs-br_test on the host; then use "ovs-vsctl list-ports virtual switch name" to get all port names on the openvSwitch virtual switch (including tun network devices, veth network devices, and physical network card devices). For example, you can get that the openvSwitch virtual switch of ovs-br_test has two tun devices (vnet26 and vnet27). Then use "ip-br a|grep'^e'" to obtain the name and status of the physical network card on the host, for example, get the name (eno1, eno2) and status (UP) list of all physical network cards on the host.

[0088] Therefore, from the above specific implementation example, all virtual machines on the host machine, as well as the correspondence between the virtual network card in each virtual machine and the tun device on the host machine can be obtained; from 3, 4, 5, and 6, all bridges and virtual switches on the host machine, as well as which physical network cards and tun devices are connected to each bridge and virtual switch, can be obtained; finally, the topological relationship between the virtual machines, tun devices, bridges, virtual switches, and physical network cards on the host machine can be obtained.

[0089] The steps of confirming the network device information in the network namespace where each container is located to lock the veth device used when each container is running, and establishing a network topology diagram of the container around the veth device include:

[0090] SB121: Obtain network device information of each container in the namespace through the instance process ID of the container;

[0091] SB122: Search the network device information for a network device number of a veth device corresponding to the container in the network namespace;

[0092] SB123: Lock the target veth device based on the network device number of the veth device;

[0093] SB124: Obtain all bridges and virtual switches associated with the container and the target veth device on the host machine to form a network topology diagram of the container.

[0094] In a specific embodiment, the statement "docker inspect -f'{{.State.Pid}}{{.State.Status}}'container name" can be used to obtain the process pid and running status corresponding to the container. For example, the process number of the process where the container centos_docker1 is located is 20601; then a statement similar to "nsenter -nt PID ip link" is used to obtain the network device information in the network name space where the container is located through the process number of the container instance. For example, the network device number (9) of the veth type virtual network card (eht0) in the network name space and the network device number (10) of the veth device corresponding to it on the host can be obtained; then the basic information of all veth network devices on the host can be obtained through the statement "ip link show type veth". For example, three veth devices and network device numbers (7, 8, 10) can be listed here; after the above steps, the names of all docker container instances on the host, the veth type virtual network card in each container instance and the network device number of its corresponding veth device on the host can be obtained. And you can get the names of all veth devices on the host and their network device numbers. Finally, you can get the correspondence between the virtual network card in the docker container instance and the veth device on the host.

[0095] It should be noted that in the K8S-based container host environment, it is easy to obtain the pod information and the name of the docker container instance running in each pod. This is because the pod and the Docker container instance in the pod are in the same network name space, so the correspondence between the internal virtual network card obtained from the docker container instance and the veth device on the host is the correspondence between each pod in the K8S environment and the veth network port device on the host; and all the bridges and virtual switches on the host can be obtained, as well as which physical network cards and veth devices are connected to each bridge and virtual switch; finally, the topological relationship between the Pod / docker container, veth device, bridge, virtual switch, and physical network card on the host is obtained.

[0096] Step S130 is a process of monitoring the Tun device based on the network topology relationship diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and a process of monitoring the veth device based on the network topology relationship diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device.

[0097] Wherein, if the whole method is implemented by a remote monitoring program, the step of monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device includes:

[0098] Obtain the Tun device receiving and sending data statistics of each Tun device through a preset Tun device monitoring command; the Tun device receiving and sending data statistics include the number of bytes received / sent, the number of packets, and the number of error packets;

[0099] Confirm the correspondence between the virtual machine and the Tun device based on the network topology diagram of the virtual machine, and integrate the statistical information of the sent and received data of the Tun device to form the Tun device data statistical information;

[0100] Using the Tun device data statistics information as the network receiving and sending status of the virtual machine corresponding to the Tun device;

[0101] If the whole is implemented by a monitoring program, the step of monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device includes:

[0102] The monitoring program directly monitors the Tun devices corresponding to the virtual machines based on the network topology of the virtual machines to obtain the real-time traffic data of each Tun device, and uses the actual traffic data as the network receiving and sending status of the corresponding virtual machines.

[0103] The monitoring method of the monitoring program is not described here. If a remote monitoring program is used, in a specific embodiment, firstly, "ip-s link show type tun" is used as the preset Tun device monitoring command to obtain the statistical information of the transceived data of all Tun network devices on the host. Then, the statistical information such as the transceived data (RX: bytes packets, TX: bytes packets) of the Tun device obtained according to the network topology diagram of the virtual machine is the network transceived data statistics of the virtual machine corresponding to the tun device.

[0104] The step of monitoring the veth device based on the network topology diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device includes:

[0105] SB131: Get the veth device sending and receiving data of each veth device through the preset veth device monitoring command;

[0106] SB132: Integrate the data sent and received by all veth devices on the network topology diagram of the container to form veth device data statistics information;

[0107] SB133: Use the veth device data statistics information as the network receiving and sending status of the container corresponding to the veth device.

[0108] In a specific embodiment, "ip-s link show type veth" can be used to obtain the statistical information of the transceiver data of all veth network devices on the host. According to the topological relationship in and, the statistical information such as the transceiver data (RX: bytes packets, TX: bytes packets) of the veth device obtained is the network transceiver data statistics such as the container / Pod corresponding to the veth.

[0109] Step S4 is a process of encapsulating the network receiving and sending status of the virtual machine and the network receiving and sending status of the container to form host monitoring data, such as Figure 8 As shown, the network transceiver status of the virtual machine and the network transceiver status of the container are character data states, which can be directly used as the network transceiver status and will not be described in detail here.

[0110] In this way, there is no need to deploy monitoring programs on each virtual machine, container / Pod, nor to rely on the data mirroring, SFlow, NetFlow, OpenFlow and other functions of the virtual switch to count the network data statistics (total number of packets sent and received, total number of bytes, number of error packets, number of lost packets) of all virtual machines, Pod / docker containers. Through regular queries, the instance traffic (bps and pps sent and received) of each virtual machine, Pod / docker container can be derived. In the end, only one command is needed to obtain the network data statistics of all virtual machines, containers / Pods in the host, greatly simplifying the way to monitor the network data of virtual machines, Pod / docker containers in the host.

[0111] In short, running a libpcap-based listening program on the host machine to monitor data on Tun and veth devices, or giving Python's remote monitoring program can realize functions such as monitoring and forwarding of real-time network data of specified virtual machines, Pod / docker containers.

[0112] As described above, the method for monitoring the internal network of a host provided by the present invention first obtains information of all virtual machines and containers in the host, then determines the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establishes a network topology relationship diagram of the virtual machine around the Tun network device, obtains the process and running status of each container according to the information of the container, confirms the network device information in the network namespace where each container is located based on the process and running status to lock the veth device used when each container is running, and establishes a network topology relationship diagram of the container around the veth device, and then monitors the Tun device based on the network topology relationship diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; based on the container The network topology diagram monitors the veth device to obtain the network receiving and sending status of the container corresponding to the veth device, thereby encapsulating the network receiving and sending status of the virtual machine and the container to form the host monitoring data. This method does not need to deploy a monitoring program on each virtual machine, container / Pod, nor does it rely on the data mirroring, SFlow, NetFlow, OpenFlow and other functions of the virtual switch to count the network data statistics of all virtual machines, Pod / docker containers (total number of packets sent and received, total number of bytes, number of error packets, number of lost packets), and the instance traffic (bps and pps sent and received) of each virtual machine, Pod / docker container can be derived through the scheduled query function of the monitoring program and the listening program. That is, only one command is needed to obtain the network data statistics of all virtual machines, containers / Pods in the host, greatly reducing the maintenance cost of monitoring the network data of virtual machines, Pod / docker containers in the host.

[0113] like Fig. 9 As shown, the present invention also provides a host internal network monitoring system 100, which implements the host internal network monitoring method as described above, including:

[0114] The information acquisition unit 101 is used to acquire information of all virtual machines and containers in the host machine;

[0115] The device positioning unit 102 is used to determine the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establish a network topology relationship diagram of the virtual machine around the Tun network device; and obtain the process and running status of each container according to the information of the container, confirm the network device information in the network namespace where each container is located according to the process and running status to lock the veth device used when each container is running, and establish the network topology relationship diagram of the container around the veth device;

[0116] The data monitoring unit 103 is used to monitor the Tun device based on the network topology relationship diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and to monitor the veth device based on the network topology relationship diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device.

[0117] The data encapsulation unit 104 is used to encapsulate the network receiving and sending status of the virtual machine and the network receiving and sending status of the container to form host monitoring data.

[0118] The information acquisition unit 101, the device positioning unit 102, the data monitoring unit 103, and the data encapsulation unit 104 are integrated in a preset remote monitoring program or a monitoring program, wherein:

[0119] If integrated in the remote monitoring program, the remote monitoring program directly uploads the host machine monitoring data to a monitoring platform connected to the remote monitoring program;

[0120] If integrated into the monitoring program, it also includes a data forwarding unit; the data forwarding unit is used to forward the host monitoring data out of the host through direct connection or tunnel encapsulation to enable the user to complete third-party monitoring.

[0121] The specific implementation method is referred to the embodiment of the host internal network monitoring method described above, which will not be described in detail here.

[0122] As described above, the monitoring system of the host machine internal network provided by the present invention first obtains the information of all virtual machines and containers in the host machine by the information acquisition unit 101, and then determines the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card according to the information of the virtual machine through the device positioning unit 102, and establishes a network topology relationship diagram of the virtual machine around the Tun network device, obtains the process and running status of each container according to the information of the container, confirms the network device information in the network namespace where each container is located based on the process and running status to lock the veth device used when each container is running, and establishes a network topology relationship diagram of the container around the veth device, and then monitors the Tun device based on the network topology relationship diagram of the virtual machine through the data monitoring unit 103 to obtain the network of the virtual machine corresponding to the Tun device Receiving and sending status; Based on the network topology diagram of the container, the veth device is monitored to obtain the network receiving and sending status of the container corresponding to the veth device, so that the network receiving and sending status of the virtual machine and the container are encapsulated through the data encapsulation unit 104 to form the host monitoring data. This method does not need to deploy a monitoring program in each virtual machine, container / Pod, nor does it need to rely on the data mirroring, SFlow, NetFlow, OpenFlow and other functions of the virtual switch to count the network data statistics of all virtual machines, Pod / docker containers (total number of packets sent and received, total number of bytes, number of error packets, number of lost packets), and the instance traffic (bps and pps of receiving and sending) of each virtual machine, Pod / docker container can be derived through the timing query function of the monitoring program and the listening program. That is, only one command is needed to obtain the network data statistics of all virtual machines, containers / Pods in the host, greatly reducing the maintenance cost of monitoring the network data of virtual machines, Pod / docker containers in the host.

[0123] As described above, the host internal network monitoring method and system proposed by the present invention are described by way of example with reference to the accompanying drawings. However, those skilled in the art should understand that various improvements can be made to the host internal network monitoring method and system proposed by the present invention without departing from the content of the present invention. Therefore, the protection scope of the present invention should be determined by the content of the attached claims.

Claims

1. A method for monitoring an internal network of a host machine, characterized in that: include: Get information about all virtual machines and containers on the host; Determine the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card based on the virtual machine information, and establish a network topology relationship diagram of the virtual machine inside the host machine around the Tun network device; and obtain the process and running status of each container based on the container information, confirm the network device information in the network namespace where each container is located based on the process and running status to lock the veth device used by each container when running, and establish a network topology relationship diagram of the container inside the host machine around the veth device; Monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and, monitoring the veth device based on the network topology diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device; The network receiving and sending status of the virtual machine and the network receiving and sending status of the container are encapsulated to form host monitoring data.

2. The method for monitoring the internal network of a host machine according to claim 1, wherein: The monitoring method is implemented by a remote monitoring program or a direct monitoring program; wherein, The remote monitoring program runs on a preset remote monitoring platform; The monitoring program runs on the host machine.

3. The method for monitoring the internal network of a host machine according to claim 2, wherein: The host monitoring data includes network data statistics of virtual machines and containers, as well as network traffic data of virtual machines and containers; wherein the network data statistics include internal network status and topology relationship data of the virtual machines and containers; If the host machine monitoring data is network data statistics of a virtual machine or container, the monitoring method is implemented by a remote monitoring program, and the remote monitoring program uploads the network data statistics to a monitoring platform connected to the remote monitoring program; If the host monitoring data is network traffic data of a virtual machine or a container, the monitoring method is implemented by the monitoring program, and the monitoring method further includes: The network traffic data is forwarded to a third-party data analysis and monitoring platform through direct connection or tunnel encapsulation.

4. The method for monitoring the internal network of a host machine according to claim 3, wherein: The process of obtaining information about all virtual machines on the host includes: Obtain the names of all virtual machines in the host machine through the preset name acquisition command, and obtain the virtual network card information corresponding to each virtual machine name; wherein the virtual network card information includes the model, name, and Mac address of the virtual network card; Querying the Tun device information corresponding to the virtual machine name through the virtual network card information, and using the Tun device information and virtual network card information corresponding to each virtual machine as the information of the respective virtual machine; wherein the Tun device information includes the name of the Tun device and the bridge information connected to the Tun device; The process of obtaining information about all containers on the host includes: Get the name list of all containers in the host through the preset list acquisition command, and use all the name lists as container information.

5. The method for monitoring the internal network of a host machine according to claim 4, wherein: The steps of determining a virtual network card corresponding to each virtual machine and a Tun network device corresponding to the virtual network card according to the information of the virtual machine, and establishing a network topology diagram of the virtual machine around the Tun network device include: Extracting the virtual network card name from the virtual machine information, and retrieving the Tun device information associated with the virtual network card name to locate the Tun network device corresponding to each virtual machine in the host machine; Based on the bridge information, a correspondence between each virtual machine, virtual network card name, Tun network device, bridge, and physical network card is established to form a network topology diagram of the virtual machine.

6. The method for monitoring the internal network of a host machine according to claim 5, wherein: The steps of confirming the network device information in the network namespace where each container is located to lock the veth device used when each container is running, and establishing a network topology diagram of the container around the veth device include: Obtain the network device information of each container in the namespace through the instance process ID of the container; Searching the network device information for a network device number of a veth device corresponding to the container in the network namespace; Lock the target veth device based on the network device number of the veth device; Obtain all bridges and virtual switches on the host machine that are associated with the container and the target veth device to form a network topology diagram of the container.

7. The method for monitoring the internal network of a host machine according to claim 6, wherein: If implemented by a remote monitoring program, the step of monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device includes: Obtain the Tun device receiving and sending data statistics of each Tun device through the preset Tun device monitoring command; the Tun device receiving and sending data statistics include the number of bytes received / sent, the number of packets, and the number of error packets; Confirm the correspondence between the virtual machine and the Tun device based on the network topology diagram of the virtual machine, and integrate the statistical information of the sent and received data of the Tun device to form Tun device data statistical information; Using the Tun device data statistics information as the network receiving and sending status of the virtual machine corresponding to the Tun device; If implemented by a monitoring program, the step of monitoring the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device includes: The monitoring program directly monitors the Tun devices corresponding to the virtual machines based on the network topology relationship of the virtual machines to obtain real-time traffic data of each Tun device, and uses the actual traffic data as the network receiving and sending status of the corresponding virtual machines.

8. The method for monitoring the internal network of a host machine according to claim 7, wherein: The step of monitoring the veth device based on the network topology diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device includes: Obtain the veth device sending and receiving data of each veth device through the preset veth device monitoring command; Integrate the data sent and received by all veth devices on the network topology diagram of the container to form veth device data statistics; The veth device data statistics information is used as the network receiving and sending status of the container corresponding to the veth device.

9. A monitoring system for a host machine's internal network, characterized in that: Implementing the host machine internal network monitoring method according to claims 1-8, comprising: An information acquisition unit, used to obtain information about all virtual machines and containers in the host machine; a device positioning unit, configured to determine, based on the virtual machine information, the virtual network card corresponding to each virtual machine and the Tun network device corresponding to the virtual network card, and establish a network topology diagram of the virtual machine within the host machine around the Tun network device; and, based on the container information, obtain the process and running status of each container, confirm the network device information within the network namespace where each container is located based on the process and running status to lock the veth device used by each container during runtime, and establish a network topology diagram of the container within the host machine around the veth device; A data monitoring unit is configured to monitor the Tun device based on the network topology diagram of the virtual machine to obtain the network receiving and sending status of the virtual machine corresponding to the Tun device; and to monitor the veth device based on the network topology diagram of the container to obtain the network receiving and sending status of the container corresponding to the veth device. The data encapsulation unit is used to encapsulate the network receiving and sending status of the virtual machine and the network receiving and sending status of the container to form host monitoring data.

10. The host internal network monitoring system according to claim 9, wherein: The information acquisition unit, the device positioning unit, the data monitoring unit, and the data encapsulation unit are integrated into a preset remote monitoring program or a monitoring program, wherein: If integrated into the remote monitoring program, the remote monitoring program directly uploads the host machine monitoring data to a monitoring platform connected to the remote monitoring program; If integrated into the monitoring program, it also includes a data forwarding unit; the data forwarding unit is used to forward the network traffic data to a third-party data analysis and monitoring platform through direct connection or tunnel encapsulation.

Citation Information

Cited By

  • Simulation system and device based on virtualized Ethernet card

    CN120342922A