summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2020-05-01 16:55:09 -0400
committerLuke Smith <luke@lukesmith.xyz>2020-05-01 16:55:09 -0400
commit77b65299475513c1c40b4ddade9897e20dac8d6a (patch)
treeca0b2becaf74d9700aeaf080bda07789f1dfd200 /.local/bin/statusbar
parent4e385c18b1e92d79f273964c327ed2320902bbcb (diff)
downloadeibhear-77b65299475513c1c40b4ddade9897e20dac8d6a.tar.gz
eibhear-77b65299475513c1c40b4ddade9897e20dac8d6a.tar.zst
eibhear-77b65299475513c1c40b4ddade9897e20dac8d6a.zip
optional network traffic module
Diffstat (limited to '.local/bin/statusbar')
-rwxr-xr-x.local/bin/statusbar/nettraf24
1 files changed, 24 insertions, 0 deletions
diff --git a/.local/bin/statusbar/nettraf b/.local/bin/statusbar/nettraf
new file mode 100755
index 0000000..64b239f
--- /dev/null
+++ b/.local/bin/statusbar/nettraf
@@ -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"