Created
January 22, 2024 19:40
-
-
Save ingmarioalberto/ee6ac9f24f23c76aa0fe7b17da64f093 to your computer and use it in GitHub Desktop.
network monitor without any requirements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#improved from https://www.commandlinefu.com/commands/view/10095/network-traffic-on-nics-in-mbps-without-sar-iperf-etc... | |
while true; do | |
[ -z ${TX2} ] && TX2=0 | |
[ -z ${RX2} ] && RX2=0 | |
[ -z ${INTERFACE} ] && INTERFACE=$(ip link | egrep -e '^[0-9]+:' | grep -v 'lo:' | grep -v 'state DOWN'| cut -d " " -f2 | cut -d ":" -f1 | head -n1) && echo "INTERFACE=${INTERFACE}" | |
RX1=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes` | |
TX1=`cat /sys/class/net/${INTERFACE}/statistics/tx_bytes` | |
DOWN=$(($RX1-$RX2)) | |
UP=$(($TX1-$TX2)) | |
DOWN_Bits=$(($DOWN * 8 )) | |
UP_Bits=$(($UP * 8 )) | |
DOWNmbps=$(( $DOWN_Bits >> 20 )) | |
UPmbps=$(($UP_Bits >> 20 )) | |
echo -e "RX:${DOWN}\tTX:${UP} B/s | RX:${DOWNmbps}\tTX:${UPmbps} Mb/s" | |
RX2=$RX1; TX2=$TX1 | |
sleep 1; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment