-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeQuality.sh
More file actions
283 lines (216 loc) · 8.83 KB
/
NodeQuality.sh
File metadata and controls
283 lines (216 loc) · 8.83 KB
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
#!/bin/bash
current_time="$(date +%Y_%m_%d_%H_%M_%S)"
work_dir=".nodequality$current_time"
bench_os_url="https://github.com/LloydAsp/NodeQuality/releases/download/v0.0.1/BenchOs.tar.gz"
raw_file_prefix="https://raw.githubusercontent.com/LloydAsp/NodeQuality/refs/heads/main"
if uname -m | grep -Eq 'arm|aarch64'; then
bench_os_url="https://github.com/LloydAsp/NodeQuality/releases/download/v0.0.1/BenchOs-arm.tar.gz"
fi
header_info_filename=header_info.log
basic_info_filename=basic_info.log
yabs_json_filename=yabs.json
ip_quality_filename=ip_quality.log
ip_quality_json_filename=ip_quality.json
net_quality_filename=net_quality.log
net_quality_json_filename=net_quality.json
backroute_trace_filename=backroute_trace.log
backroute_trace_json_filename=backroute_trace.json
port_filename=port.log
function start_ascii(){
echo -ne "\e[1;36m"
cat <<- EOF
███╗ ██╗ ██████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ █████╗ ██╗ ██╗████████╗██╗ ██╗
████╗ ██║██╔═══██╗██╔══██╗██╔════╝██╔═══██╗██║ ██║██╔══██╗██║ ██║╚══██╔══╝╚██╗ ██╔╝
██╔██╗ ██║██║ ██║██║ ██║█████╗ ██║ ██║██║ ██║███████║██║ ██║ ██║ ╚████╔╝
██║╚██╗██║██║ ██║██║ ██║██╔══╝ ██║▄▄ ██║██║ ██║██╔══██║██║ ██║ ██║ ╚██╔╝
██║ ╚████║╚██████╔╝██████╔╝███████╗╚██████╔╝╚██████╔╝██║ ██║███████╗██║ ██║ ██║
╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝
Benchmark script for server, collects basic hardware information, IP quality and network quality
The benchmark will be performed in a temporary system, and all traces will be deleted after that.
Therefore, it has no impact on the original environment and supports almost all linux systems.
Author: Lloyd@nodeseek.com
Github: github.com/LloydAsp/NodeQuality
Command: bash <(curl -sL https://run.NodeQuality.com)
EOF
echo -ne "\033[0m"
}
function _red() {
echo -e "\033[0;31m$1\033[0m"
}
function _yellow() {
echo -e "\033[0;33m$1\033[0m"
}
function _blue() {
echo -e "\033[0;36m$1\033[0m"
}
function _green() {
echo -e "\033[0;32m$1\033[0m"
}
function _red_bold() {
echo -e "\033[1;31m$1\033[0m"
}
function _yellow_bold() {
echo -e "\033[1;33m$1\033[0m"
}
function _blue_bold() {
echo -e "\033[1;36m$1\033[0m"
}
function _green_bold() {
echo -e "\033[1;32m$1\033[0m"
}
function pre_init(){
mkdir -p "$work_dir"
cd $work_dir
work_dir="$(pwd)"
}
function pre_cleanup(){
# incase interupted last time
clear_mount
if [[ "$work_dir" == *"nodequality"* ]]; then
rm -rf "${work_dir}"/*
else
echo "Error: work_dir does not contain 'nodequality'!"
exit 1
fi
}
function clear_mount(){
swapoff $work_dir/swap 2>/dev/null
umount $work_dir/BenchOs/proc/ 2> /dev/null
umount $work_dir/BenchOs/sys/ 2> /dev/null
umount -R $work_dir/BenchOs/dev/ 2> /dev/null
}
function load_bench_os(){
cd $work_dir
rm -rf BenchOs
curl "-L#o" BenchOs.tar.gz $bench_os_url
tar -xzf BenchOs.tar.gz
cd $work_dir/BenchOs
mount -t proc /proc proc/
mount --bind /sys sys/
mount --rbind /dev dev/
mount --make-rslave dev
rm etc/resolv.conf 2>/dev/null
cp /etc/resolv.conf etc/resolv.conf
}
function chroot_run(){
chroot $work_dir/BenchOs /bin/bash -c "$*"
}
function load_part(){
# gb5-test.sh, swap part
. <(curl -sL "$raw_file_prefix/part/swap.sh")
}
function load_3rd_program(){
chroot_run wget https://github.com/nxtrace/NTrace-core/releases/download/v1.3.7/nexttrace_linux_amd64 -qO /usr/local/bin/nexttrace
chroot_run chmod u+x /usr/local/bin/nexttrace
}
function run_header(){
chroot_run bash <(curl -Ls "$raw_file_prefix/part/header.sh")
}
yabs_url="$raw_file_prefix/part/yabs.sh"
function run_yabs(){
if ! curl -s 'https://browser.geekbench.com' --connect-timeout 5 >/dev/null; then
chroot_run bash <(curl -sL $yabs_url) -s -- -gi -w /result/$yabs_json_filename
echo -e "对 IPv6 单栈的服务器来说进行测试没有意义,\n因为要将结果上传到 browser.geekbench.com 后才能拿到最后的跑分,\n但 browser.geekbench.com 仅有 IPv4、不支持 IPv6,测了也是白测。"
else
virt=$(dmidecode -s system-product-name 2> /dev/null || virt-what | grep -v redhat | head -n 1 || echo "none")
if [[ "${virt,,}" != "lxc" ]]; then
check_swap 1>&2
fi
# 服务器一般测geekbench5即可
chroot_run bash <(curl -sL $yabs_url) -s -- -5i -w /result/$yabs_json_filename
fi
chroot_run bash <(curl -sL $raw_file_prefix/part/sysbench.sh)
}
function run_ip_quality(){
chroot_run bash <(curl -Ls IP.Check.Place) -n -o /result/$ip_quality_json_filename
}
function run_net_quality(){
local params=""
[[ "$run_net_quality_test" =~ ^[Ll]$ ]] && params=" -L"
chroot_run bash <(curl -Ls Net.Check.Place) $params -n -o /result/$net_quality_json_filename
}
function run_net_trace(){
chroot_run bash <(curl -Ls Net.Check.Place) -R -n -S 123 -o /result/$backroute_trace_json_filename
}
uploadAPI="https://api.nodequality.com/api/v1/record"
function upload_result(){
chroot_run zip -j - "/result/*" > $work_dir/result.zip
base64 $work_dir/result.zip | curl -X POST --data-binary @- $uploadAPI
echo
}
function post_cleanup(){
chroot_run umount -R /dev &> /dev/null
clear_mount
post_check_mount
rm -rf $work_dir/BenchOs
if [[ "$work_dir" == *"nodequality"* ]]; then
rm -rf "${work_dir}"/
else
echo "Error: work_dir does not contain 'nodequality'!"
exit 1
fi
exit 1
}
function sig_cleanup(){
trap '' INT TERM SIGHUP EXIT
_red "Cleaning, please wait a moment."
post_cleanup
}
function post_check_mount(){
if mount | grep nodequality$current_time ; then
echo "出现了预料之外的情况,BenchOs目录的挂载未被清理干净,保险起见请重启后删除该目录" | tee $work_dir/error.log >&2
exit
fi
}
function ask_question(){
yellow='\033[1;33m' # Set yellow color
reset='\033[0m' # Reset to default color
echo -en "${yellow}Run Basic Info test? (Enter for default 'y') [y/n]: ${reset}"
read run_yabs_test
run_yabs_test=${run_yabs_test:-y}
echo -en "${yellow}Run IPQuality test? (Enter for default 'y') [y/n]: ${reset}"
read run_ip_quality_test
run_ip_quality_test=${run_ip_quality_test:-y}
echo -en "${yellow}Run NetQuality test? (Enter for default 'y', 'l' for low-data mode) [y/l/n]: ${reset}"
read run_net_quality_test
run_net_quality_test=${run_net_quality_test:-y}
echo -en "${yellow}Run Backroute Trace test? (Enter for default 'y') [y/n]: ${reset}"
read run_net_trace_test
run_net_trace_test=${run_net_trace_test:-y}
}
function main(){
trap 'sig_cleanup' INT TERM SIGHUP EXIT
start_ascii
ask_question
_green_bold 'Clean Up before Installation'
pre_init
pre_cleanup
_green_bold 'Load BenchOs'
load_bench_os
load_part
load_3rd_program
_green_bold 'Basic Info'
result_directory=$work_dir/BenchOs/result
mkdir -p $result_directory
run_header > $result_directory/$header_info_filename
if [[ "$run_yabs_test" =~ ^[Yy]$ ]]; then
_green_bold 'Running Basic Info Test...'
run_yabs | tee $result_directory/$basic_info_filename
fi
if [[ "$run_ip_quality_test" =~ ^[Yy]$ ]]; then
_green_bold 'Running IP Quality Test...'
run_ip_quality | tee $result_directory/$ip_quality_filename
fi
if [[ "$run_net_quality_test" =~ ^[YyLl]$ ]]; then
_green_bold 'Running Network Quality Test...'
run_net_quality | tee $result_directory/$net_quality_filename
fi
if [[ "$run_net_trace_test" =~ ^[Yy]$ ]]; then
_green_bold 'Running Backroute Trace...'
run_net_trace | tee $result_directory/$backroute_trace_filename
fi
upload_result
_green_bold 'Clean Up after Installation'
post_cleanup
}
main