关于网卡驱动统计流量的数据结构struct net_device_stats
用于统计网络设备的数据结构如下所示。rx应该是代表该网卡接受的包的相关统计,这个应该没问题。
需要明确的一个问题是:对于tx,一般情况下代表是该网卡发送包的统计。那么如果在一个多端口的网络设备中,由端口A发出,也就是发到和端口A直接相连的设备上的流量应该统计在tx里。对于由端口A转发到同一网络设备的另外一个端口的流量,是否记在tx中呢。
struct net_device_stats
{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted*/
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped;/* no space available in linux*/
unsigned long multicast; /* multicast packets received */
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow*/
unsigned long rx_crc_errors;/* recved pkt with crc error */
unsigned long rx_frame_errors;/* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors;/* receiver missed packet*/
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
/* for cslip etc */
unsigned long rx_compressed;
unsigned long tx_compressed;
}; 简单测试的情况来看tx应该指的是该网卡发送到线上的流量 通常我们在计算机上看到的网卡有发送和接受的包。对于一台多网卡主机中,其中一个网卡发送的数据包是否包括这两个方面呢:
1. 由网卡所在的宿主机构造并发送的包
2. 由其他网卡转发到该网卡,并由该网卡发送的包。
对于第2个,我还不太确定 再次测试了一下:
由其他网卡转发到该网卡,并由该网卡发送的包也算在了tx内。都统计为该网卡发送的数据 本帖最后由 iceyes342 于 2011-10-31 15:11 编辑
net_device_stats是一个网络设备(或者说是一个网络接口)只有一个这样的数据结构吗? 回复 6# iceyes342
这个函数指针应该指向具体网卡驱动中的对应实现。
因此,网卡驱动中,对哪些成员更新了,哪些就是有效的 回复 6# Godbach
那如果驱动中没有对net_device_stats里的某个属性就行更新,那么,内核会处理吗?比如rx_dropped这样的属性,还是说这个属性就不更新了…… 回复 7# iceyes342
我的理解,既然没更新,那它的值就一直不变吧 回复 8# Godbach
恩。谢谢。因为我看一个驱动没有修改rx_dropped的值,但是ifconfig的时候确实可以看到这个网卡的dropped对应的值在变化,不知道是怎么回事…… 回复 9# iceyes342
那就不对了。 ifconfig 基本上也是读取驱动中统计的结果
页:
[1]
2