aboutsummaryrefslogtreecommitdiff
path: root/segments/ifstat_sys.sh
diff options
context:
space:
mode:
authorCody Hiar <chiar@hybridforge.com>2015-08-12 12:06:23 -0600
committerCody Hiar <chiar@hybridforge.com>2015-08-12 12:06:23 -0600
commit07fc2644a237187dd4c5680e88f4adadbf533603 (patch)
treebb6335e180df48c5a6f0b893312857d36ad470f7 /segments/ifstat_sys.sh
Initial commit of the working files
Diffstat (limited to 'segments/ifstat_sys.sh')
-rwxr-xr-xsegments/ifstat_sys.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/segments/ifstat_sys.sh b/segments/ifstat_sys.sh
new file mode 100755
index 0000000..1059dc4
--- /dev/null
+++ b/segments/ifstat_sys.sh
@@ -0,0 +1,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
+}