PPS Viewer Script (Packets Per Second)

The script every second displays the number of incoming and outgoing packets per second on the specified network interface.
Place the contents of the script into a file, for example, pps.sh and execute by specifying the name of the network interface:

./pps.sh ens2f0

Script content:

#!/bin/bash
INTERVAL="1"  # update interval in seconds
 
if [ -z "$1" ]; then
        echo usage: $0 [network-interface]
        echo shows packets-per-second
        exit
fi
  
IF=$1
  
while true
do
        R1=`cat /sys/class/net/$1/statistics/rx_packets`
        T1=`cat /sys/class/net/$1/statistics/tx_packets`
        sleep $INTERVAL
        R2=`cat /sys/class/net/$1/statistics/rx_packets`
        T2=`cat /sys/class/net/$1/statistics/tx_packets`
        TXPPS=`expr $T2 - $T1`
        RXPPS=`expr $R2 - $R1`
        echo "TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s"
done
Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply