You are not logged in.
I'm putting together a bash if...then statement for dzen that will handle the display of ethernet and wireless network information and one of the things I'd like to do is list the up/down speeds of a given interface. What file should I be referencing this information?
Any help would be greatly appreciated!
thayer williams ~ cinderwick.ca
Offline
You can find some stats in /proc/net/dev
Offline
I'm putting together a bash if...then statement for dzen that will handle the display of ethernet and wireless network information and one of the things I'd like to do is list the up/down speeds of a given interface. What file should I be referencing this information?
Any help would be greatly appreciated!
I'd recoment you to use /sys/class/net/$INTERFACE/statistics/rx_bytes and /sys/class/net/$INTERFACE/statistics/tx_bytes.
So, here a very brief example:
INTERFACE=eth0
while :; do
P2=$P1
P1=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes`
echo Down: `expr $P1 - $P2` B/s
sleep 1;
doneLast edited by gotmor (2007-12-05 19:38:41)
Offline
If I am understanding this correctly, there is no way of capturing the up/down rates in a raw form. Is that right? It looks like I'll have to pass two values (snapshots at different intervals, e.g. 1 second apart) through an equation in order to calculate the current rate. I was trying to avoid that because I'd like to have the net stats embedded in a script that displays other system stats and sleeps for 5-20 seconds between updates.
Last edited by thayer (2007-12-05 21:11:30)
thayer williams ~ cinderwick.ca
Offline
I'd like to have the net stats embedded in a script that sleeps for 5-20 seconds between updates
Just keep time and stat data from last call:
function get_net_speed(){ # get_net_speed eth1 rx
CF="/sys/class/net/$1/statistics/$2_bytes"
PF="$TMP/$1-$2"
PFT="$PF-ts"
PFTV=`cat "$PFT" 2>/dev/null`
PFV=`cat "$PF" 2>/dev/null`
CFTV=`date +%s`
CFV=`cat "$CF" 2>/dev/null`
cat "$CF" > "$PF"
date +%s > "$PFT"
echo "scale=2; ( $CFV - ${PFV:-0} ) / ( $CFTV - ${PFTV:-0} ) / 1024" | bc
}
get_net_speed eth1 rx
sleep 1
get_net_speed eth1 rx
sleep 10
get_net_speed eth1 rx
sleep 7
get_net_speed eth1 rx
sleep 3
get_net_speed eth1 rxOffline
I have been using this as part of screen's status line for years:
http://code.phraktured.net/?p=config.gi … en/netinfo
Offline
Thanks for the tips, guys. Unfortunately, I couldn't the examples to work and I couldn't understand them enough to figure out why. Rob has posted a network script for dzen though so that saves me from reinventing the wheel. Cheers!
thayer williams ~ cinderwick.ca
Offline