I'm interested in creating a script which prints total number of received packets and sent packets on an interface. The output should be like:
interface TX: number RX: number
Can anyone help me please?
You can figure out the amount of packets received and transmitted across
eth0 by running the following commands:
cat /sys/class/net/eth0/statistics/rx_packets cat /sys/class/net/eth0/statistics/tx_packets
You could then use this fact to write simple a shell script which will poll these files every second, and then calculate and output a PPS value (packets per second).
I have seen some miss matches in the stats using the /sys/class/net statistics and also same with
(since it is reading stats from that files, i think). Some tools using the mentioned counters are
The correct stats i have seen is from
ethtool -S <interface> | grep -E 'rx_packets|tx_packets|rx_bytes|tx_bytes'