3

When I run the command ethtool -S wlp2s0, I get the following information:

NIC statistics:
     rx_packets: 63
     rx_bytes: 14163
     rx_duplicates: 2
     rx_fragments: 58
     rx_dropped: 30
     tx_packets: 60
     tx_bytes: 9668
     tx_filtered: 0
     tx_retry_failed: 0
     tx_retries: 39
     sta_state: 4
     txrate: 115600000
     rxrate: 130000000
     signal: 189
     channel: 0
     (...) 

However, when I go to the /sys/class/net/wlp2s0/statistics folder, the statistics are different from ethtool (and they seem to be the ones printed by ifconfig). For instance, when I display rx_dropped from the folder, the result is always 0.

This is the ifconfig display of the interface:

wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.115  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::6f9d:4eac:5bec:1ea6  prefixlen 64  scopeid 0x20<link>
        ether 88:b1:11:6a:1d:82  txqueuelen 1000  (Ethernet)
        RX packets 42483  bytes 55964467 (55.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9309  bytes 1393476 (1.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

My question is, If I wanted to know the dropped packets in 1 second intervals, where could I get that information? ethtool seems to be a good option, but I don't know where it is getting information from and I don't understand why the information is different from the statistics folder...

Also, what would that 30 value in the rx_dropped mean? Is it the dropped packets since the interface is up?

3

ethtool gets the statistics using the SIOCETHTOOL ioctl, which takes a pointer to struct ethtool_stats. To get the statistics, the cmd field of the struct should have the value ETHTOOL_GSTATS. Before calling that ioctl, you must use another ethtool ioctl (also SIOCETHTOOL, with either a pointer to struct ethtool_sset_info with its cmd field initialized to ETHTOOL_GSSET_INFO, or a pointer to struct ethtool_drvinfo with its cmd field initialized to ETHTOOL_GDRVINFO) to know the number of different statistics values the driver is about to return, so you can allocate enough memory for struct ethtool_stats.

...And if you don't program in C, the very dense, jargon-rich description above probably did not make any sense at all to you. If you need to access ethtool statistics in a script, I would recommend using a scripting language that has bindings for the ethtool interface available, like Perl (module Linux::Ethtool) or Python (apparently https://pypi.org/project/netifaces/). Those should make accessing the statistics much more straightforward.

Of course you can always parse the output of the ethtool command, but if you want to poll the statistics once every second, it might be beneficial to eliminate the need to vfork() a new process or two every time you need the statistics.

The resulting values come from the NIC driver. The fact that the driver developer hasn't added the code to access the relevant statistics also via /sys/class/net/<name>/statistics nor via /proc/net/dev where ifconfig gets them from suggests that the driver might define those values somewhat differently than /proc/net/dev and/or /sys/class/net/*/statistics... or it might simply indicate that the driver implementation is unfortunately not perfect.

(The developer may have chosen to implement the ethtool API first, since it is the newest one, and left the older statistics interfaces incomplete for "when I have the time." Also note that the ifconfig command is being deprecated by most distributions since it is not well maintained any more.)

To find out the details, you may have to read the documentation and/or the source code comments of the actual driver. As you did not specify the NIC model nor the name of the driver, nobody else can do it for you. The output of ethtool -i wlp2s0 would be of great use in identifying the NIC driver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.