2
2
3
3
INTERVAL=" 1" # update interval in seconds
4
4
5
- network_name=$( tmux show-option -gqv " @tmux2k-network-bandwidth" )
5
+ # Network interface to monitor
6
+ network_name=" en0"
7
+
8
+ if [[ $( uname -s) == " Darwin" ]]; then
9
+ network_name=" en0" # en0 is wifi, TODO: Update network_name
10
+ elif [[ $( uname -s) == " Linux" ]]; then
11
+ network_name=$( tmux show-option -gqv " @dracula-network-bandwidth" )
12
+ else
13
+ # update this later for window
14
+ echo " Unknown operating system"
15
+ exit 1
16
+ fi
6
17
7
18
main () {
8
19
while true
@@ -12,40 +23,50 @@ main() {
12
23
output_download_unit=" "
13
24
output_upload_unit=" "
14
25
15
- initial_download=$( cat /sys/class/net/" $network_name " /statistics/rx_bytes)
16
- initial_upload=$( cat /sys/class/net/" $network_name " /statistics/tx_bytes)
26
+ if [[ $( uname -s) == " Linux" ]]; then
27
+ initial_download=$( cat /sys/class/net/" $network_name " /statistics/rx_bytes)
28
+ initial_upload=$( cat /sys/class/net/" $network_name " /statistics/tx_bytes)
29
+
30
+ sleep " $INTERVAL "
17
31
18
- sleep " $INTERVAL "
32
+ final_download=$( cat /sys/class/net/" $network_name " /statistics/rx_bytes)
33
+ final_upload=$( cat /sys/class/net/" $network_name " /statistics/tx_bytes)
34
+ else
35
+ initial_download=$( netstat -I " $network_name " -b | tail -n 1 | awk ' {print $7}' )
36
+ initial_upload=$( netstat -I " $network_name " -b | tail -n 1 | awk ' {print $10}' )
19
37
20
- final_download=$( cat /sys/class/net/" $network_name " /statistics/rx_bytes)
21
- final_upload=$( cat /sys/class/net/" $network_name " /statistics/tx_bytes)
38
+ sleep $INTERVAL
39
+
40
+ final_download=$( netstat -I " $network_name " -b | tail -n 1 | awk ' {print $7}' )
41
+ final_upload=$( netstat -I " $network_name " -b | tail -n 1 | awk ' {print $10}' )
42
+ fi
22
43
23
- total_download_bps=$( expr " $final_download " - " $initial_download " )
24
- total_upload_bps=$( expr " $final_upload " - " $initial_upload " )
44
+ total_download_bps=$( expr $final_download - $initial_download )
45
+ total_upload_bps=$( expr $final_upload - $initial_upload )
25
46
26
- if [ " $total_download_bps " -gt 1073741824 ]; then
47
+ if [ $total_download_bps -gt 1073741824 ]; then
27
48
output_download=$( echo " $total_download_bps 1024" | awk ' {printf "%.2f \n", $1/($2 * $2 * $2)}' )
28
49
output_download_unit=" gB/s"
29
- elif [ " $total_download_bps " -gt 1048576 ]; then
50
+ elif [ $total_download_bps -gt 1048576 ]; then
30
51
output_download=$( echo " $total_download_bps 1024" | awk ' {printf "%.2f \n", $1/($2 * $2)}' )
31
52
output_download_unit=" mB/s"
32
53
else
33
54
output_download=$( echo " $total_download_bps 1024" | awk ' {printf "%.2f \n", $1/$2}' )
34
55
output_download_unit=" kB/s"
35
56
fi
36
57
37
- if [ " $total_upload_bps " -gt 1073741824 ]; then
58
+ if [ $total_upload_bps -gt 1073741824 ]; then
38
59
output_upload=$( echo " $total_download_bps 1024" | awk ' {printf "%.2f \n", $1/($2 * $2 * $2)}' )
39
60
output_upload_unit=" gB/s"
40
- elif [ " $total_upload_bps " -gt 1048576 ]; then
61
+ elif [ $total_upload_bps -gt 1048576 ]; then
41
62
output_upload=$( echo " $total_upload_bps 1024" | awk ' {printf "%.2f \n", $1/($2 * $2)}' )
42
63
output_upload_unit=" mB/s"
43
64
else
44
65
output_upload=$( echo " $total_upload_bps 1024" | awk ' {printf "%.2f \n", $1/$2}' )
45
66
output_upload_unit=" kB/s"
46
67
fi
47
68
48
- echo " ↓ $output_download $output_download_unit • ↑ $output_upload $output_upload_unit "
69
+ echo " ↓ $output_download$output_download_unit • ↑ $output_upload$output_upload_unit "
49
70
done
50
71
}
51
72
main
0 commit comments