-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsngbench.sh
executable file
·342 lines (263 loc) · 7.97 KB
/
sngbench.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
338
339
340
341
342
#!/usr/bin/env bash
set -euf -o pipefail
script_dir="$(dirname "$(realpath "$0")")"
input_file="${script_dir}/input.txt"
config_dir="${script_dir}/conf"
output_dir_prefix="${script_dir}/out"
output_dir=''
syslog_ng=''
syslog_ng_ctl=''
syslog_ng_loggen=''
test_run_count=3
print_error()
{
printf '%s\n' "$*" >&2
}
print_begin()
{
local message="$1"
printf '%s...' "${message}"
}
print_done()
{
printf ' %s\n' 'Done.'
}
get_executable_path()
{
local executable_name="$1"
local executable_path
executable_path="$(command -v "${executable_name}" || true)"
if [[ -z "${executable_path}" ]]
then
print_error "Executable '${executable_name}' not found!" 'Exiting...'
exit 1
fi
printf '%s' "${executable_path}"
}
check_prerequisites()
{
local prerequisites=(
'cp'
'date'
'grep'
'head'
'loggen'
'mkdir'
'pgrep'
'syslog-ng'
'syslog-ng-ctl'
'timeout'
'uname'
)
print_begin 'Checking prerequisites'
for prerequisite in "${prerequisites[@]}"
do
get_executable_path "${prerequisite}" > /dev/null
done
print_done
}
setup_output_dir()
{
output_dir="${output_dir_prefix}/$(date '+%Y-%m-%d_%H-%M-%S')"
if [[ -d "${output_dir}" ]]
then
print_error \
"Output directory ('${output_dir}') already exists!" \
'Exiting...'
exit 2
fi
printf '%s\n' "Results will be saved into '${output_dir}'."
mkdir -p "${output_dir}"
for ((i=0; i < test_run_count; i++))
do
mkdir "${output_dir}/run_$((i + 1))"
done
}
set_syslog_ng_paths()
{
syslog_ng="$(get_executable_path 'syslog-ng')"
syslog_ng_ctl="$(get_executable_path 'syslog-ng-ctl')"
syslog_ng_loggen="$(get_executable_path 'loggen')"
}
save_system_info()
{
print_begin 'Saving system info'
"${syslog_ng}" --version > "${output_dir}/syslog-ng.version"
uname -a > "${output_dir}/uname.out"
for _file in '/etc/os-release' '/proc/cpuinfo'
do
if [[ -f "${_file}" ]]
then
cp "${_file}" "${output_dir}/"
fi
done
print_done
}
stop_syslog_ng()
{
local timeout_in_sec="${1:-60}"
local syslog_ng_pids
local exit_status=0
print_begin 'Stopping syslog-ng'
syslog_ng_pids="$(pgrep 'syslog-ng' || true)"
if [[ -n "${syslog_ng_pids}" ]]
then
"${syslog_ng_ctl}" \
stop \
>> "${output_dir}/syslog-ng-ctl.out" 2>&1 \
|| true
fi
timeout "${timeout_in_sec}" \
/usr/bin/env bash -c "until ! \"${syslog_ng_ctl}\" stats > /dev/null 2>&1 ; do sleep 1; done" \
|| exit_status="$?"
if ((exit_status != 0))
then
print_error \
"Could not stop syslog-ng in ${timeout_in_sec} seconds!" \
'Exiting...'
exit 3
fi
print_done
}
wait_for_syslog_ng_to_start()
{
local timeout_in_sec="${1:-60}"
local exit_status=0
timeout "${timeout_in_sec}" \
/usr/bin/env bash -c "until \"${syslog_ng_ctl}\" stats > /dev/null 2>&1 ; do sleep 1 ; done" \
|| exit_status="$?"
if ((exit_status != 0))
then
print_error \
"syslog-ng did not start in ${timeout_in_sec} seconds!" \
'Exiting...'
exit 3
fi
}
get_file_names_in_directory_by_extension()
{
local directory="$1"
local extension=".$2"
(
cd "${directory}"
set +f
for _file in $(printf '%s\n' *"${extension}")
do
printf '%s\n' "$_file"
done
set -f
)
}
run_benchmark()
{
local log_files_to_remove=(
'/var/log/fromnet1'
'/var/log/fromnet2'
'/var/log/fromnet3'
'/var/log/fromnet4'
)
for ((i=0; i < test_run_count; i++))
do
printf '%s\n' "Test run #$((i + 1)):"
while IFS= read -r line
do
config_name="${line/,*/}"
loggen_parameters_list=()
loggen_pids=()
print_begin "Starting syslog-ng with config '${config_dir}/${config_name}'"
"${syslog_ng}" \
--no-caps \
-f "${config_dir}/${config_name}" \
>> "${output_dir}/syslog-ng.out" 2>&1
wait_for_syslog_ng_to_start 10
print_done
IFS=',' read -r -a loggen_parameters_list <<< "${line#*,}"
for ((j=0; j < ${#loggen_parameters_list[@]}; j++))
do
loggen_parameter_list="${loggen_parameters_list[${j}]}"
loggen_output_path="${loggen_parameter_list// /_}"
loggen_output_path="${loggen_output_path//-/}"
loggen_output_path="${loggen_output_path//=/_}"
loggen_output_path="${output_dir}/run_$((i + 1))/${config_name}.${loggen_output_path}.$((j + 1)).csv"
loggen_arguments=()
IFS=' ' read -r -a loggen_arguments <<< "${loggen_parameter_list}"
print_begin "Starting loggen #$((j + 1))"
"${syslog_ng_loggen}" "${loggen_arguments[@]}" &> "${loggen_output_path}" &
loggen_pids+=($!)
print_done
done
for ((j=0; j < ${#loggen_pids[@]}; j++))
do
print_begin "Waiting for loggen #$((j + 1))"
wait "${loggen_pids["${j}"]}"
print_done
done
stop_syslog_ng 10
for log_file_to_remove in "${log_files_to_remove[@]}"
do
rm -f "${log_file_to_remove}" || true
done
done < "${input_file}"
done
}
sum_results()
{
local result_file_list
local result_files=()
local result_file_lists=()
local output_file="${output_dir}/results.csv"
print_begin 'Processing results'
for ((i=0; i < test_run_count; i++))
do
result_file_lists+=("$(get_file_names_in_directory_by_extension "${output_dir}/run_$((i + 1))" 'csv')")
done
result_file_list="${result_file_lists[0]}"
for other_result_file_list in "${result_file_lists[@]}"
do
if [[ "${result_file_list}" != "${other_result_file_list}" ]]
then
print_error \
'The number of result files is different between test runs!' \
'Exiting...'
exit 4
fi
done
mapfile -t result_files <<< "${result_file_list}"
for result_file in "${result_files[@]}"
do
config_name="${result_file/.*/}"
loggen_parameters="${result_file#*.}"
loggen_parameters="${loggen_parameters%.*}"
loggen_parameters="${loggen_parameters%.*}"
loggen_num="${result_file%.*}"
loggen_num="${loggen_num##*.}"
printf \
'%s' \
"${config_name},${loggen_parameters},${loggen_num}" \
>> "${output_file}"
measured_values=''
for ((i=0; i < test_run_count; i++))
do
_stat="$(
grep 'average rate' "${output_dir}/run_$((i + 1))/${result_file}" \
| head -1
)"
_stat="${_stat##*average rate = }"
_stat="${_stat%% *}"
measured_values="${measured_values},${_stat}"
done
printf '%s\n' "${measured_values}" >> "${output_file}"
done
print_done
}
main()
{
check_prerequisites
set_syslog_ng_paths
setup_output_dir
stop_syslog_ng 10
save_system_info
run_benchmark
sum_results
}
main