-
Notifications
You must be signed in to change notification settings - Fork 0
/
l4z2.bash
executable file
·224 lines (193 loc) · 3.58 KB
/
l4z2.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
INTERFACE=wlp3s0
d1=$(cat /sys/class/net/wlp3s0/statistics/rx_bytes)
u1=$(cat /sys/class/net/wlp3s0/statistics/tx_bytes)
declare -a IDLE_TIME
declare -a IDLE_OLD_TIME
declare -a SUMS
declare -a SUMS_OLD
declare -a CPU_NAME
declare -a CPU_USAGE
touch avgdownload.txt
touch avgupload.txt
printDownSpeed()
{
d2=$(cat /sys/class/net/wlp3s0/statistics/rx_bytes)
DOWN=$((d2-d1))
AVG_DOWN=0
if [ $DOWN -gt 0 ]
then
echo >> avgdownload.txt $DOWN
fi
if [ -s avgdownload.txt ]
then
AVG_DOWN=$(awk '{sum += $1} END { printf("%.0f", sum/NR) }' avgdownload.txt)
fi
DOWN_SUFFIX="B/s"
if [ $DOWN -gt 1024 ] #1024 * 1024
then
DOWN=$((DOWN/1024))
DOWN_SUFFIX="KB/s"
fi
if [ $DOWN -gt 1024 ]
then
DOWN=$((DOWN/1024))
DOWN_SUFFIX="MB/s"
fi
AVG_DOWN_SUFFIX="B\s"
if [ $AVG_DOWN -gt 1024 ]
then
AVG_DOWN=$((AVG_DOWN/1024))
AVG_DOWN_SUFFIX="KB/s"
fi
if [ $AVG_DOWN -gt 1024 ]
then
AVG_DOWN=$((AVG_DOWN/1024))
AVG_DOWN_SUFFIX="MB/s"
fi
echo "DOWN SPEED: $DOWN $DOWN_SUFFIX"
echo "AVG DOWN SPEED: $AVG_DOWN $AVG_DOWN_SUFFIX"
d1=$d2
}
printUpSpeed()
{
u2=$(cat /sys/class/net/wlp3s0/statistics/tx_bytes)
UP=$((u2-u1))
AVG_UP=0
if [ $UP -gt 0 ]
then
echo >> avgupload.txt $UP
fi
if [ -s avgupload.txt ]
then
AVG_UP=$(awk '{sum += $1} END { printf("%.0f", sum/NR) }' avgupload.txt)
fi
UP_SUFFIX="B/s"
AVG_UP_SUFFIX="B/s"
if [ $UP -gt 1024 ] #1024 * 1024
then
UP=$((UP/1024))
UP_SUFFIX="KB/s"
fi
if [ $UP -gt 1024 ]
then
UP=$((UP/1024))
UP_SUFFIX="MB/s"
fi
if [ $AVG_UP -gt 1024 ]
then
AVG_UP=$((AVG_UP/1024))
AVG_UP_SUFFIX="KB/s"
fi
if [ $AVG_UP -gt 1024 ]
then
AVG_UP=$((AVG_UP/1024))
AVG_UP_SUFFIX="MB/s"
fi
echo "UP SPEED: $UP $UP_SUFFIX"
echo "AVG UP SPEED: $AVG_UP $AVG_UP_SUFFIX"
u1=$u2
}
getCpuInfo()
{
IDLE_OLD_TIME=("${IDLE_TIME[@]}")
SUMS_OLD=("${SUMS[@]}")
local x=0
local CPU_NUMBER=0
#reset variables
SUMS=()
IDLE_TIME=()
for i in $(cat /proc/stat | grep cpu)
do
{
if [ $x -eq 11 ]
then
x=0
CPU_NUMBER=$((CPU_NUMBER+1))
fi
if [ $x -eq 0 ]
then
CPU_NAME[$CPU_NUMBER]=$i
fi
if [ $x -lt 12 ]
then
SUMS[$CPU_NUMBER]=$((${SUMS[$CPU_NUMBER]}+i))
if [ $x -eq 4 ]
then
IDLE_TIME[$CPU_NUMBER]=$i
fi
fi
x=$((x+1))
};done
}
printCpuUsage()
{
getCpuInfo
local NOT_USED_PERCENT
local LENGTH=${#CPU_NAME[@]}
local DELTA_SUM
local DELTA_IDLE
for i in `seq 0 $((LENGTH-1))`
do
{
local OLD_SUM=${SUMS_OLD[$i]}
local NEW_SUM=${SUMS[$i]}
DELTA_SUM=$((NEW_SUM-OLD_SUM))
local OLD_IDLE=${IDLE_OLD_TIME[$i]}
local NEW_IDLE=${IDLE_TIME[$i]}
DELTA_IDLE=$((NEW_IDLE-OLD_IDLE))
NOT_USED_PERCENT=$((DELTA_IDLE*100/DELTA_SUM))
USED_PERCENT=$((100-NOT_USED_PERCENT))
echo -n "${CPU_NAME[$i]}: $USED_PERCENT% "
};done
echo ""
}
printCpuFrequency()
{
local x=0
for i in $(grep 'processor\|cpu\ MHz' /proc/cpuinfo)
do
{
if [ $x -lt 7 ]
then
echo -n "$i " >> demo
else
echo "" >> demo
x=0
fi
x=$((x+1))
};done
column -t -s : demo
rm demo
}
printUptime()
{
awk '{print "\nUPTIME: " int($1/86400)"d "int(($1%86400)/3600)"h "int((($1%86400)%3600)/60)"m "int((($1%86400)%3600)%60)"s"}' /proc/uptime
}
printBatteryLevel ()
{
awk '{print "BATTERY LEVEL: " $1 "%"}' /sys/class/power_supply/BAT0/capacity
}
printAvgLoad()
{
awk '{print "AVG LOAD PER: "$1"-1min "$2"-5min "$3"-15min"}' /proc/loadavg
}
printMemInfo()
{
printf "$(grep Mem /proc/meminfo)"
}
while sleep 1
do
{
clear
printDownSpeed
printUpSpeed
printCpuUsage
printCpuFrequency
printUptime
printBatteryLevel
printAvgLoad
printMemInfo
};done
rm avgdownload.txt
rm avgupload.txt