mirror of
https://github.com/TECHNOFAB11/tmux2k.git
synced 2025-12-11 23:50:08 +01:00
Merge pull request #2 from shubhamku044/mac-network_bandwidth
fix: network_bandwidth for mac
This commit is contained in:
commit
d2491d15a3
1 changed files with 34 additions and 13 deletions
|
|
@ -2,7 +2,18 @@
|
||||||
|
|
||||||
INTERVAL="1" # update interval in seconds
|
INTERVAL="1" # update interval in seconds
|
||||||
|
|
||||||
network_name=$(tmux show-option -gqv "@tmux2k-network-bandwidth")
|
# Network interface to monitor
|
||||||
|
network_name="en0"
|
||||||
|
|
||||||
|
if [[ $(uname -s) == "Darwin" ]]; then
|
||||||
|
network_name="en0" # en0 is wifi, TODO: Update network_name
|
||||||
|
elif [[ $(uname -s) == "Linux" ]]; then
|
||||||
|
network_name=$(tmux show-option -gqv "@dracula-network-bandwidth")
|
||||||
|
else
|
||||||
|
# update this later for window
|
||||||
|
echo "Unknown operating system"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
while true
|
while true
|
||||||
|
|
@ -12,21 +23,31 @@ main() {
|
||||||
output_download_unit=""
|
output_download_unit=""
|
||||||
output_upload_unit=""
|
output_upload_unit=""
|
||||||
|
|
||||||
initial_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
|
if [[ $(uname -s) == "Linux" ]]; then
|
||||||
initial_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
|
initial_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
|
||||||
|
initial_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
|
||||||
|
|
||||||
sleep "$INTERVAL"
|
sleep "$INTERVAL"
|
||||||
|
|
||||||
final_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
|
final_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
|
||||||
final_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
|
final_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
|
||||||
|
else
|
||||||
|
initial_download=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $7}')
|
||||||
|
initial_upload=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $10}')
|
||||||
|
|
||||||
total_download_bps=$(expr "$final_download" - "$initial_download")
|
sleep $INTERVAL
|
||||||
total_upload_bps=$(expr "$final_upload" - "$initial_upload")
|
|
||||||
|
|
||||||
if [ "$total_download_bps" -gt 1073741824 ]; then
|
final_download=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $7}')
|
||||||
|
final_upload=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $10}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
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=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
||||||
output_download_unit="gB/s"
|
output_download_unit="gB/s"
|
||||||
elif [ "$total_download_bps" -gt 1048576 ]; then
|
elif [ $total_download_bps -gt 1048576 ]; then
|
||||||
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
||||||
output_download_unit="mB/s"
|
output_download_unit="mB/s"
|
||||||
else
|
else
|
||||||
|
|
@ -34,10 +55,10 @@ main() {
|
||||||
output_download_unit="kB/s"
|
output_download_unit="kB/s"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$total_upload_bps" -gt 1073741824 ]; then
|
if [ $total_upload_bps -gt 1073741824 ]; then
|
||||||
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
||||||
output_upload_unit="gB/s"
|
output_upload_unit="gB/s"
|
||||||
elif [ "$total_upload_bps" -gt 1048576 ]; then
|
elif [ $total_upload_bps -gt 1048576 ]; then
|
||||||
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
||||||
output_upload_unit="mB/s"
|
output_upload_unit="mB/s"
|
||||||
else
|
else
|
||||||
|
|
@ -45,7 +66,7 @@ main() {
|
||||||
output_upload_unit="kB/s"
|
output_upload_unit="kB/s"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "↓ $output_download $output_download_unit • ↑ $output_upload $output_upload_unit"
|
echo "↓ $output_download$output_download_unit • ↑ $output_upload$output_upload_unit"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
main
|
main
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue