8f05c7d79f
* More precise RAM measurement and fix of memory type * Should be KiB kB refers to https://en.wikipedia.org/wiki/Kibibyte
25 lines
907 B
Bash
Executable file
25 lines
907 B
Bash
Executable file
#!/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" ;;
|
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
|
esac
|
|
|
|
rxfile="${XDG_CACHE_HOME:-$HOME/.cache}/rxlog"
|
|
txfile="${XDG_CACHE_HOME:-$HOME/.cache}/txlog"
|
|
|
|
rxcurrent="$(cat /sys/class/net/*/statistics/rx_bytes | paste -sd '+' | bc)"
|
|
txcurrent="$(cat /sys/class/net/*/statistics/tx_bytes | paste -sd '+' | bc)"
|
|
|
|
printf "🔻%sKiB 🔺%sKiB\\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"
|