Skip to content

Instantly share code, notes, and snippets.

@parthpower
Last active August 26, 2021 11:19
Show Gist options
  • Save parthpower/b4f70b85774d944a51ac03ce6d37130e to your computer and use it in GitHub Desktop.
Save parthpower/b4f70b85774d944a51ac03ce6d37130e to your computer and use it in GitHub Desktop.
get rate from netdev stats
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Usage: $0 <ifname> [delay (s) default=10s]";
exit 1;
fi
eth=$1
if [ "x$2" -eq "x" ]; then
delay=10
else
delay=$2
fi
arx=$(cat /sys/class/net/$eth/statistics/rx_bytes);
atx=$(cat /sys/class/net/$eth/statistics/tx_bytes);
sleep $delay;
btx=$(cat /sys/class/net/$eth/statistics/tx_bytes);
brx=$(cat /sys/class/net/$eth/statistics/rx_bytes);
echo rx: $(( ($brx - $arx)/$delay/1024 )) kBps
echo tx: $(( ($btx - $atx)/$delay/1024 )) kBps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment