forked from RunOnFlux/fluxnode-multitool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardwarebench.sh
337 lines (326 loc) · 13.2 KB
/
hardwarebench.sh
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/env bash
SSD=0
HDD=0
SCORE=0
GREEN='\033[1;32m'
NC='\033[0m'
CYAN='\033[1;36m'
command_exists()
{
command -v "$@" > /dev/null 2>&1
}
Bps_to_MiBps()
{
awk '{ printf "%.2f\n", $0 / 1024 / 1024 } END { if (NR == 0) { print "error" } }'
}
B_to_MiB()
{
awk '{ printf "%.0f MiB\n", $0 / 1024 / 1024 } END { if (NR == 0) { print "error" } }'
}
finish()
{
printf '\n'
sudo rm -f test_$$
exit
}
trap finish EXIT INT TERM
dd_benchmark()
{
cd $HOME && sudo LC_ALL=C timeout 30s dd if=/dev/zero of=$1/test_$$ bs=64k count=16k conv=fdatasync 2>&1 | \
awk -F, '
{
io=$NF
}
END {
if (io ~ /TB\/s/) {printf("%.0f\n", 1000*1000*1000*1000*io)}
else if (io ~ /GB\/s/) {printf("%.0f\n", 1000*1000*1000*io)}
else if (io ~ /MB\/s/) {printf("%.0f\n", 1000*1000*io)}
else if (io ~ /KB\/s/) {printf("%.0f\n", 1000*io)}
else { printf("%.0f", 1*io)}
}'
sudo rm -f $1/test_*
}
if ! command_exists dd; then
printf '%s\n' 'This script requires dd, but it could not be found.' 1>&2
exit 1
fi
if [[ "$(sysbench --version)" == "" ]]; then
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sed 's/dist=${dist}/dist=focal/g' | sudo bash > /dev/null 2>&1
sudo apt -y install sysbench > /dev/null 2>&1
if [[ "$(sysbench --version)" == "" ]]; then
echo -e ""
echo -e "-------------------------------------------"
echo -e "| HARDWARE BENCHMARK"
echo -e "-------------------------------------------"
echo -e "| Benchmark: FAILED"
echo -e "| Error: Sysbench installation failed..."
echo -e "-------------------------------------------"
echo -e ""
exit
fi
fi
vcore=$(getconf _NPROCESSORS_ONLN)
ram=$(LC_ALL=C free -b 2> /dev/null | awk 'NR==2 {print $2}' | grep -Eo '[0-9]+'| printf "%.0f\n" $(awk '{ print $1/1024/1024/1024 }') 2> /dev/null )
core=$(awk -F: '/cpu cores/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \\t]*//;s/[ \\t]*$//')
if [[ "$core" == "" ]]; then
core=$(grep 'processor' /proc/cpuinfo | wc -l)
fi
echo -e ""
echo -e "-------------------------"
echo -e "| MEMORY BENCHMARK"
echo -e "-------------------------"
echo -e "| RAM: ${CYAN}${ram}${NC}"
echo -e "-------------------------"
echo -e "| CPU BENCHMARK"
echo -e "-------------------------"
eps=$(LC_ALL=C sysbench cpu --cpu-max-prime=60000 --time=20 run 2> /dev/null | grep 'events per second' | awk -v cpu=$vcore '{print $4*cpu}')
if [[ "$(dpkg --print-architecture)" = *"Jetson"* ]]; then
cumulus_ram=3
else
cumulus_ram=7
fi
if [[ "$ram" -ge "$cumulus_ram" ]] && [[ "$core" -ge 2 ]] && [[ "$vcore" -ge 4 ]] && [[ "${eps%%.*}" -ge 240 ]]; then
status="CUMULUS"
fi
if [[ "$ram" -ge 30 ]] && [[ "$core" -ge 4 ]] && [[ "$vcore" -ge 8 ]] && [[ "${eps%%.*}" -ge 640 ]]; then
status="NIMBUS"
fi
if [[ "$ram" -ge 61 ]] && [[ "$core" -ge 8 ]] && [[ "$vcore" -ge 16 ]] && [[ "${eps%%.*}" -ge 1520 ]]; then
status="STRATUS"
fi
if [[ "$status" == "" ]]; then
status="FAILED"
fi
echo -e "| CPU vcores: ${CYAN}${vcore}${NC}"
echo -e "| CPU cores: ${CYAN}${core}${NC}"
echo -e "| EPS: ${CYAN}${eps}${NC}"
outputdiskbench="Disks Bench:";
#checking loop for lxc only if mount == '/'
loop_mount=$(cd $HOME && LC_ALL=C lsblk -l -b -n | grep ' loop' | awk '{ if ($7 == "/") printf("%.2f\n", $4/(1024*1024*1024))}')
if [[ "$loop_mount" != "" ]]; then
#echo -e "Device type: loop"
mount_path="/"
io1=$( dd_benchmark "$mount_path" )
io2=$( dd_benchmark "$mount_path" )
io3=$( dd_benchmark "$mount_path" )
if [[ "$io1" -le "$io2" ]] && [[ "$io1" -le "$io3" ]]; then
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io2"' + '"$io3"')/2)}' | Bps_to_MiBps )
elif [[ "$io2" -le "$io1" ]] && [[ "$io2" -le "$io3" ]]; then
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io1"' + '"$io3"')/2)}' | Bps_to_MiBps )
else
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io1"' + '"$io2"')/2)}' | Bps_to_MiBps )
fi
outputdiskbench+=" loop $loop_mount $ioavg"
if [[ "${ioavg%%.*}" -ge "180" ]]; then
SSD=$(awk 'BEGIN{printf("%d",'"$SSD"'+'"$loop_mount"')}')
else
HDD=$(awk 'BEGIN{printf("%d",'"$HDD"'+'"$loop_mount"')}')
fi
fi
if [[ $outputdiskbench == "Disks Bench:" ]]; then
lvm_mount=""
raid_list=()
disc__array=($(cd $HOME && LC_ALL=C lsblk -o NAME,SIZE,TYPE -b -n | grep ' disk' | awk '{ if ($2 > 2147483648 && $1 != "mmcblk0" && $1 != "mmcblk0p1") print $1}'))
for((i=0;i<${#disc__array[@]};i++));
do
#checking if disk structure is accessable
cd $HOME && lsblk -l -b -n /dev/${disc__array[i]} > /dev/null 2>&1
if [ $? != 0 ]; then
#echo -e "Disk name: ${disc__array[i]}"
#echo -e "Error: Can't grab device stucture... device skipped!"
#echo -e "-----------------------------"
continue
fi
#checking direct mount
disk_mount_check=$(cd $HOME && LC_ALL=C lsblk -l -b -n /dev/${disc__array[i]} | grep ' disk' | awk '{ if ( $7 == "") print "no"; else print "yes"}')
#echo -e "Direct mount: $disk_mount_check"
if [[ "$disk_mount_check" == "no" ]]; then
#checking lvm mount
lvm_mount=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | egrep ' lvm| dm' | tail -n1 | awk '{ print $7 }' )
lvm_name=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | egrep ' lvm| dm' | tail -n1 | awk '{ print $1 }' )
if [[ "$lvm_name" != "" ]]; then
count=$(echo ${mount_list[@]} | tr ' ' '\n' | awk '$1 == "'"$lvm_mount"'"{print $0}' | wc -l)
if [[ "$count" == "0" ]]; then
mount_list+=("$lvm_mount")
else
#echo -e "Disk name: ${disc__array[i]}"
#echo -e "Error: Mount point already checked... device skipped!"
#echo -e "-----------------------------"
continue
fi
fi
if [[ "$lvm_name" != "" && "$lvm_mount" == "" ]]; then
if [[ ! -d /.benchmark_test ]]; then
sudo mkdir /.benchmark_test
fi
sudo mount /dev/mapper/$lvm_name /.benchmark_test
fi
lvm_mount=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | egrep ' lvm| dm' | tail -n1 | awk '{ print $7 }' )
if [[ "$lvm_mount" != "" ]]; then
partition_output=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | egrep ' lvm| dm' | tail -n1 | awk '{print $1 " " $4/(1024*1024*1024) }')
else
#checking if disk partition type is LVM2_member
part_type_check=$(cd $HOME && LC_ALL=C lsblk -o NAME,TYPE,FSTYPE,SIZE -b -n /dev/${disc__array[i]} --sort SIZE | egrep ' part' | egrep 'LVM2_member' | tail -n1 | wc -l)
if [[ "$part_type_check" != "0" ]]; then
#skipp disk
partition_name=$(awk '{print $1}' <<< $part_type_check)
#echo -e "Disk name: ${disc__array[i]}"
#echo -e "Error: LVM2_member partition detected... device skipped!"
#echo -e "-----------------------------"
continue
fi
#checking raid
partition_output=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | egrep ' raid' | tail -n1 | awk '{print $1 " " $4/(1024*1024*1024) }')
if [[ "$partition_output" == "" ]]; then
#checking part ( when not lvm and raid )
#echo -e "Checking partition on device: /dev/${disc__array[i]}"
partition_output=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | egrep ' part' | tail -n1 | awk '{print $1 " " $4/(1024*1024*1024) }')
#echo -e "$partition_output"
#echo -e "-----------------------------"
else
partition_name=$(awk '{print $1}' <<< $partition_output)
#add raid name to skip list
if [[ ! " ${raid_list[@]} " =~ " ${partition_name} " ]]; then
raid_list+=("$partition_name")
else
#skipped raid already tested
#echo -e "Disk name: ${disc__array[i]}"
#echo -e "Info: Disk skipped - raid already tested!"
#echo -e "-----------------------------"
continue
fi
fi
fi
else
#echo -e "Checking partition on device: /dev/${disc__array[i]} (STEP2)..."
partition_output=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --sort SIZE | tail -n1 | awk '{print $1 " " $4/(1024*1024*1024) }')
#echo -e "$partition_output"
#echo -e ""
fi
partition_name=$(awk '{print $1}' <<< $partition_output)
partition_size=$(awk '{printf("%.2f",$2)}' <<< $partition_output)
if [[ "$lvm_mount" == "" && "$raid_list" == "" ]]; then
disk_size=$(cd $HOME && LC_ALL=C lsblk -l -b /dev/${disc__array[i]} --noheadings | head -n1 | awk '{printf("%.2f",$4/(1024*1024*1024))}')
else
disk_size=$partition_size
fi
if [[ "$lvm_mount" == "" ]]; then
if [[ ! -d /.benchmark_test ]]; then
sudo mkdir /.benchmark_test
fi
sudo mount /dev/$partition_name /.benchmark_test
available_space=$(LC_ALL=C df /dev/$partition_name | grep $partition_name | tail -n1 | awk '{ if ($4 > 2097152) printf("%.2f",$4/(1024*1024)); else print "null"}')
else
available_space=$(LC_ALL=C df /dev/mapper/$partition_name | grep $partition_name | tail -n1 | awk '{ if ($4 > 2097152) printf("%.2f",$4/(1024*1024)); else print "null"}')
fi
if [[ "$available_space" != "null" && "$available_space" != "" ]]; then
if [[ "$lvm_mount" == "" ]]; then
mount_path="/.benchmark_test"
else
mount_path="$lvm_mount"
fi
#echo -e "Mount point: $mount_path"
io1=$( dd_benchmark "$mount_path" )
io2=$( dd_benchmark "$mount_path" )
io3=$( dd_benchmark "$mount_path" )
if [[ "$io1" -le "$io2" ]] && [[ "$io1" -le "$io3" ]]; then
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io2"' + '"$io3"')/2)}' | Bps_to_MiBps )
elif [[ "$io2" -le "$io1" ]] && [[ "$io2" -le "$io3" ]]; then
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io1"' + '"$io3"')/2)}' | Bps_to_MiBps )
else
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io1"' + '"$io2"')/2)}' | Bps_to_MiBps )
fi
outputdiskbench+=" ${disc__array[i]} $disk_size $ioavg"
if [[ "${ioavg%%.*}" -ge "180" ]]; then
SSD=$(awk 'BEGIN{printf("%d",'"$SSD"'+'"$disk_size"')}')
else
HDD=$(awk 'BEGIN{printf("%d",'"$HDD"'+'"$disk_size"')}')
fi
if [[ "$lvm_mount" == "" ]]; then
sudo umount /.benchmark_test
if [[ $(cd $HOME && lsblk -l | grep "benchmark_test") ]]; then
echo -e ""
else
sudo rm -rf /.benchmark_test
fi
fi
#check if test point mounted if exist unmount it LVM case
if [[ $(cd $HOME && lsblk -l | grep "benchmark_test") ]]; then
sudo umount /.benchmark_test
if [[ $(cd $HOME && lsblk -l | grep "benchmark_test") ]]; then
echo -e ""
else
sudo rm -rf /.benchmark_test
fi
fi
else
#echo -e "Error: space not enough... write test skipped!"
#echo -e "-----------------------------"
if [[ "$lvm_mount" == "" ]]; then
sudo umount /.benchmark_test
if [[ $(cd $HOME && lsblk -l | grep "benchmark_test") ]]; then
echo -e ""
else
sudo rm -rf /.benchmark_test
fi
fi
fi
done
if [[ "$outputdiskbench" == "Disks Bench:" ]]; then
# lsblk failed checking direct mount from df
df_direct_mount=$(LC_ALL=C df --output=source,fstype,size,avail,target | grep 'dev' | awk '{ if ($5 == "/") printf("%s %.2f %.2f\n", $1,$3/(1024*1024),$4/(1024*1024))}')
if [[ df_direct_mount != "" ]]; then
device_name=$(awk '{print $1}' <<< $df_direct_mount)
partition_size=$(awk '{print $2}' <<< $df_direct_mount)
mount_path="/"
io1=$( dd_benchmark "$mount_path" )
io2=$( dd_benchmark "$mount_path" )
io3=$( dd_benchmark "$mount_path" )
if [[ "$io1" -le "$io2" ]] && [[ "$io1" -le "$io3" ]]; then
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io2"' + '"$io3"')/2)}' | Bps_to_MiBps )
elif [[ "$io2" -le "$io1" ]] && [[ "$io2" -le "$io3" ]]; then
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io1"' + '"$io3"')/2)}' | Bps_to_MiBps )
else
ioavg=$( awk 'BEGIN{printf("%.0f", ('"$io1"' + '"$io2"')/2)}' | Bps_to_MiBps )
fi
outputdiskbench+=" $device_name $partition_size $ioavg"
if [[ "${ioavg%%.*}" -ge "180" ]]; then
SSD=$(awk 'BEGIN{printf("%d",'"$SSD"'+'"$partition_size"')}')
else
HDD=$(awk 'BEGIN{printf("%d",'"$HDD"'+'"$partition_size"')}')
fi
fi
fi
fi
echo -e "-------------------------"
echo -e "| DISK BENCHMARK"
echo -e "-------------------------"
echo -e "| SSD: ${CYAN}${SSD}${NC}"
echo -e "| HDD: ${CYAN}${HDD}${NC}"
echo -e "-------------------------"
if [[ $status == "CUMULUS" ]]; then
SCORE=1
fi
if [[ $status == "NIMBUS" ]]; then
SCORE=2
fi
if [[ $status == "STRATUS" ]]; then
SCORE=3
fi
if [[ "$SSD" -lt 220 ]] || [[ "$SCORE" == 0 ]] ; then
status="FAILED"
fi
if [[ "$SSD" -ge 220 ]] && [[ "$SCORE" -ge 1 ]]; then
status="${GREEN}CUMULUS${NC}"
fi
if [[ "$HDD" -ge 9200 ]] && [[ "$SCORE" -ge 1 ]]; then
status="${GREEN}THUNDER${NC}"
fi
if [[ "$SSD" -ge 440 ]] && [[ "$SCORE" -ge 2 ]]; then
status="${GREEN}NIMBUS${NC}"
fi
if [[ "$SSD" -ge 880 ]] && [[ "$SCORE" -ge 3 ]] ; then
status="${GREEN}STRATUS${NC}"
fi
echo -e "| Benchmark: $status"
echo -e "-------------------------"