环境
- Time 2022-11-25
- WSL-Ubuntu 22.04
前言
说明
参考:https://docs.kernel.org/networking/statistics.html
目标
前一节讲了 ethtool 命令获取网卡和统计信息,ip 命令也可以获取一些数据包的信息。
显示信息
ip -s -s link show dev dev_name
命令可以显示网卡的统计信息:
root@jiangbo12490:~# ip -s -s link show dev eth0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:15:5d:0f:ca:04 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped missed mcast
335787159 227541 0 0 0 1693
RX errors: length crc frame fifo overrun
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
7630852 110020 0 0 0 0
TX errors: aborted fifo window heartbt transns
0 0 0 0 1
一般来说,RX 表示接收,TX 表示发送。
RX
rx_bytes
Number of good received bytes, corresponding to rx_packets.
收到的字节数,和 rx_packets
对应。
rx_packets
Number of good packets received by the interface. For hardware interfaces counts all good packets received from the device by the host, including packets which host had to drop at various stages of processing (even in the driver).
网卡接口接收到的正常数据包数量。硬件接口统计主机从设备接收的所有正常数据包,包括主机在不同处理阶段(甚至在驱动程序中)必须丢弃的数据包。
rx_errors
Total number of bad packets received on this network device. This counter must include events counted by rx_length_errors, rx_crc_errors, rx_frame_errors and other errors not otherwise counted.
此网络设备上接收的坏数据包总数。这个记录数必须包括由 length_errors、crc_errors、frame_errors 和其他未知错误数。
rx_dropped
Number of packets received but not processed, e.g. due to lack of resources or unsupported protocol. For hardware interfaces this counter may include packets discarded due to L2 address filtering but should not include packets dropped by the device due to buffer exhaustion which are counted separately in rx_missed_errors.
接收但未处理的数据包数量,例如,由于资源不足或协议不受支持。对于硬件接口,此计数可能包括由于二层地址过滤而丢弃的数据包,但不应包括由于缓冲区耗尽而由设备丢弃的数据,这些数据包在 rx_missed 中单独计数。
rx_missed
Count of packets missed by the host. Counts number of packets dropped by the device due to lack of buffer space. This usually indicates that the host interface is slower than the network interface, or host is not keeping up with the receive packet rate. This statistic corresponds to hardware events and is not used on software devices.
主机丢失的数据包计数。统计设备由于缓冲区空间不足而丢弃的数据包数。这通常表示主机接口比网络接口慢,或者主机跟不上接收包速率。此统计信息对应于硬件事件,不用于软件设备。
rx_mcast
Multicast packets received. For hardware interfaces this statistic is commonly calculated at the device level (unlike rx_packets) and therefore may include packets which did not reach the host.
接收到的多播数据包。对于硬件接口,此统计通常在设备级计算(与 rx_packets 不同),因此可能包括未到达主机的数据包。
rx_length_errors
Number of packets dropped due to invalid length.
由于长度无效而丢弃的数据包数。
rx_crc_errors
Number of packets received with a CRC error.
接收到 CRC 错误的数据包数。
rx_frame_errors
Receiver frame alignment errors.
接收到帧对齐错误的数据包。
rx_fifo_errors
Receiver FIFO error counter. Historically the count of overflow events. Those events may be reported in the receive descriptors or via interrupts, and may not correspond one-to-one with dropped packets.
This statistics was used interchangeably with rx_over_errors. Not recommended for use in drivers for high speed interfaces. This statistic is used on software devices, e.g. to count software packet queue overflow (can) or sequencing errors (GRE).
接收到 FIFO 错误的数据包。之前用来做溢出事件的计数。这些事件可以在接收描述符中或通过中断来报告,并且可能与丢弃的数据包不是一一对应。
此统计数据与 rx_over_errors 之前互换使用。不建议在高速接口的驱动程序中使用。该统计数据用于软件设备,例如用于软件层数据包队列溢出或序列号错误。
rx_over_errors
Receiver FIFO overflow event counter. Historically the count of overflow events. Such events may be reported in the receive descriptors or via interrupts, and may not correspond one-to-one with dropped packets.
The recommended interpretation for high speed interfaces is - number of packets dropped because they did not fit into buffers provided by the host, e.g. packets larger than MTU or next buffer in the ring was not available for a scatter transfer.
This statistics was historically used interchangeably with rx_fifo_errors. This statistic corresponds to hardware events and is not commonly used on software devices.
接收到 FIFO 错误的数据包。之前用来做溢出事件的计数。这些事件可以在接收描述符中或通过中断来报告,并且可能与丢弃的数据包不是一一对应。
高速接口的建议解释是:由于数据包不适配主机提供的缓冲区而丢弃的数据包数量,例如,大于 MTU 的数据包或环中的下一个缓冲区不可用于旁路传输。
此统计数据与 rx_fifo_errors 之前互换使用。不建议在高速接口的驱动程序中使用。该统计数据对应于硬件事件,不常用于软件设备。
TX
tx_bytes
传送的字节数,和 tx_packets
对应。
tx_packets
Number of packets successfully transmitted. For hardware interfaces counts packets which host was able to successfully hand over to the device, which does not necessarily mean that packets had been successfully transmitted out of the device, only that device acknowledged it copied them out of host memory.
成功传输的数据包数。对于硬件接口,统计主机能够成功交给设备的数据包,这并不一定意味着数据包已成功从设备中传输出去,只有确切该设备已将数据包从主机内存中复制出去。
tx_errors
Total number of transmit problems. This counter must include events counter by tx_aborted_errors, tx_carrier_errors, tx_fifo_errors, tx_heartbeat_errors, tx_window_errors and other errors not otherwise counted.
传输出错的数据包总数。此计数必须包括事件计数器,包括 tx_aborted_errors、tx_carrier_errors、tx_fifo_errors、tx_heartbeat_errors 和 tx_window_errors 以及其他未知的错误。
tx_dropped
Number of packets dropped on their way to transmission, e.g. due to lack of resources.
在传输中丢弃的数据包数量,例如由于资源不足。
tx_carrier
Number of frame transmission errors due to loss of carrier during transmission.
传输过程中由于载波丢失而导致的帧传输错误数。
tx_collsns
Number of collisions during packet transmissions.
传输期间冲突的数据包数量。
tx_aborted_errors
High speed interfaces may use this counter as a general device discard counter.
高速接口可将此计数用作通用设备丢弃计数。
tx_fifo_errors
Number of frame transmission errors due to device FIFO underrun/underflow. This condition occurs when the device begins transmission of a frame but is unable to deliver the entire frame to the transmitter in time for transmission. Part of aggregate “carrier” errors in /proc/net/dev.
由于设备 FIFO 不足或下溢导致的帧传输错误数。当设备开始传输帧但不能及时将整个帧传送给传输者进行传输时,就会出现这种情况。
tx_window_errors
Number of frame transmission errors due to late collisions (for Ethernet - after the first 64B of transmission).
延迟冲突导致的帧传输错误数(对于以太网-在第一次 64B 传输之后)。
tx_heartbeat_errors
Number of Heartbeat / SQE Test errors for old half-duplex Ethernet.
旧半双工以太网的心跳/SQE 测试错误数。
总结
介绍了 IP 命令对于数据包的统计。