Merge pull request #133 from foxtrot/step-bandwidth-units
Show network bandwidth in gB/s and mB/s when required
This commit is contained in:
commit
cce69791b6
1 changed files with 27 additions and 3 deletions
|
@ -7,6 +7,11 @@ network_name=$(tmux show-option -gqv "@dracula-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)
|
||||
|
||||
|
@ -18,10 +23,29 @@ main() {
|
|||
total_download_bps=$(expr $final_download - $initial_download)
|
||||
total_upload_bps=$(expr $final_upload - $initial_upload)
|
||||
|
||||
total_download_kbps=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
|
||||
total_upload_kbps=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
|
||||
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
|
||||
|
||||
echo "↓ $total_download_kbps kB/s • ↑ $total_upload_kbps kB/s"
|
||||
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…
Reference in a new issue