optional network traffic module
This commit is contained in:
parent
4e385c18b1
commit
77b6529947
1 changed files with 24 additions and 0 deletions
24
.local/bin/statusbar/nettraf
Executable file
24
.local/bin/statusbar/nettraf
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Module showing network traffic. Shows how much data has been received (RX) or
|
||||
# transmitted (TX) since the previous time this script ran. So if run every
|
||||
# second, gives network traffic per second.
|
||||
|
||||
case "$BLOCK_BUTTON" in
|
||||
3) notify-send "🌐 Network traffic module" "🔻: Traffic received
|
||||
🔺: Traffic transmitted" ;;
|
||||
esac
|
||||
|
||||
rxfile="${XDG_CACHE_HOME:-$HOME/.cache}/rxlog"
|
||||
txfile="${XDG_CACHE_HOME:-$HOME/.cache}/txlog"
|
||||
|
||||
rxcurrent="$(cat /sys/class/net/*/statistics/rx_bytes | tr '\n' '+' | sed 's/+$/\n/' | bc)"
|
||||
txcurrent="$(cat /sys/class/net/*/statistics/tx_bytes | tr '\n' '+' | sed 's/+$/\n/' | bc)"
|
||||
|
||||
printf "🔻%skB 🔺%skB\\n" \
|
||||
"$(printf -- "(%s-%s)/1024\\n" "$rxcurrent" "$(cat "$rxfile")" | bc)" \
|
||||
"$(printf -- "(%s-%s)/1024\\n" "$txcurrent" "$(cat "$txfile")" | bc)"
|
||||
|
||||
# Log the current values for next run.
|
||||
echo "$rxcurrent" > "$rxfile"
|
||||
echo "$txcurrent" > "$txfile"
|
Loading…
Reference in a new issue