mirror of
https://github.com/TECHNOFAB11/tmux2k.git
synced 2025-12-11 23:50:08 +01:00
Add network_bandwidth.sh
This commit is contained in:
parent
42246125a4
commit
7835e24e5f
1 changed files with 51 additions and 0 deletions
51
scripts/network_bandwidth.sh
Executable file
51
scripts/network_bandwidth.sh
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
INTERVAL="1" # update interval in seconds
|
||||
|
||||
network_name=$(tmux show-option -gqv "@tmux2k-network-bandwidth")
|
||||
|
||||
main() {
|
||||
while true
|
||||
do
|
||||
output_download=""
|
||||
output_upload=""
|
||||
output_download_unit=""
|
||||
output_upload_unit=""
|
||||
|
||||
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
|
||||
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
|
||||
|
||||
sleep $INTERVAL
|
||||
|
||||
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
|
||||
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
|
||||
|
||||
total_download_bps=$(expr $final_download - $initial_download)
|
||||
total_upload_bps=$(expr $final_upload - $initial_upload)
|
||||
|
||||
if [ $total_download_bps -gt 1073741824 ]; then
|
||||
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
||||
output_download_unit="gB/s"
|
||||
elif [ $total_download_bps -gt 1048576 ]; then
|
||||
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
||||
output_download_unit="mB/s"
|
||||
else
|
||||
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
|
||||
output_download_unit="kB/s"
|
||||
fi
|
||||
|
||||
if [ $total_upload_bps -gt 1073741824 ]; then
|
||||
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
||||
output_upload_unit="gB/s"
|
||||
elif [ $total_upload_bps -gt 1048576 ]; then
|
||||
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
||||
output_upload_unit="mB/s"
|
||||
else
|
||||
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
|
||||
output_upload_unit="kB/s"
|
||||
fi
|
||||
|
||||
echo "↓ $output_download $output_download_unit • ↑ $output_upload $output_upload_unit"
|
||||
done
|
||||
}
|
||||
main
|
||||
Loading…
Add table
Add a link
Reference in a new issue