Display errors for all NICs with sysfs

Recently, while I was investigating a network issue on one of the Xen hosts in our fleet, I was curious if I could quickly gather any error or drop counters for the host’s physical NICs and numerous domU VIFs.

I could have performed a netstat -i or look at /proc/net/dev but I guess it wouldn’t be that straightforward to filter the output for the information that I might be interested in further (filtering only by TX or RX, errors or drops, counting columns and using awk can be cumbersome, etc). Therefore, I crafted a one-liner to query sysfs for this purpose, and the beauty of Unix’ philosophy of simple tools shimmered once again:

$ find /sys/class/net/*/statistics/ -type f -regex '.*\(errors\|dropped\)' -exec grep -vH "^0$" {} \;

This will display a set of *errors or *dropped files that have >0 in their content, for all the interfaces. This is easy to grep further. Stylish, no?

Comments are closed.