-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurl_time_csv.sh
executable file
·65 lines (55 loc) · 1.64 KB
/
curl_time_csv.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
#!/bin/bash
# Set the `errexit` option to make sure that
# if one command fails, all the script execution
# will also fail (see `man bash` for more
# information on the options that you can set).
set -o errexit
# This is the main routine of our bash program.
# It makes sure that we've supplied the necessary
# arguments, then it prints a CSV header and then
# keeps making requests and printing their responses.
#
# Note.: because we're calling `curl` each time in
# the loop, a new `curl` process is created for
# each request.
#
# This means that a new connection will be made
# each time.
#
# Such property might be useful when you're testing
# if a given load-balancer in the middle might be
# messing up with some requests.
main () {
local count=$1
local url=$2
if [[ -z "$url" ]]; then
echo "ERROR:
An URL must be provided.
Usage: check-res <url>
Aborting.
"
exit 1
fi
print_header
for i in `seq 1 $1`; do
make_request $url
done
}
# This method does nothing more that just print a CSV
# header to STDOUT so we can consume that later when
# looking at the results.
print_header () {
echo "code,time_total,time_connect,time_appconnect,time_prestransfer,time_starttransfer"
}
# Make request performs the actual request using `curl`.
# It specifies those parameters that we've defined before,
# taking a given `url` as its parameter.
make_request () {
local url=$1
curl \
--write-out "%{http_code},%{time_total},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_starttransfer}\n" \
--silent \
--output /dev/null \
"$url"
}
main "$@"