blob: 1059dc4a620aebb001dbee594c62a273e8995c85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# Show if stats by sampling /sys/.
# Originally stolen from http://unix.stackexchange.com/questions/41346/upload-download-speed-in-tmux-status-line
run_segment() {
sleeptime="0.5"
iface="eth0"
RXB=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXB=$(</sys/class/net/"$iface"/statistics/tx_bytes)
sleep "$sleeptime"
RXBN=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXBN=$(</sys/class/net/"$iface"/statistics/tx_bytes)
RXDIF=$(echo "$((RXBN - RXB)) / 1024 / ${sleeptime}" | bc )
TXDIF=$(echo "$((TXBN - TXB)) / 1024 / ${sleeptime}" | bc )
if [ $RXDIF -gt 1024 ]; then
RXDIF_ECHO="↓ $(echo "scale=1;${RXDIF} / 1024" | bc)M/s"
else
RXDIF_ECHO="↓ ${RXDIF}K/s"
fi
if [ $TXDIF -gt 1024 ]; then
TXDIF_ECHO="↑ $(echo "scale=1;${TXDIF} / 1024" | bc)M/s"
else
TXDIF_ECHO="↑ ${TXDIF}K/s"
fi
echo -e "${RXDIF_ECHO} ${TXDIF_ECHO}"
return 0
}
|