forked from microservices-demo/load-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runLocust.sh
executable file
·99 lines (82 loc) · 1.88 KB
/
runLocust.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
#!/bin/bash
#
# Run locust load test
#
#####################################################################
ARGS="$@"
HOST="${1}"
SCRIPT_NAME=`basename "$0"`
INITIAL_DELAY=1
TARGET_HOST="$HOST"
CLIENTS=2
REQUESTS=10
do_check() {
# check hostname is not empty
if [ "${TARGET_HOST}x" == "x" ]; then
echo "TARGET_HOST is not set; use '-h hostname:port'"
exit 1
fi
# check for locust
if [ ! `command -v locust` ]; then
echo "Python 'locust' package is not found!"
exit 1
fi
# check locust file is present
if [ -n "${LOCUST_FILE:+1}" ]; then
echo "Locust file: $LOCUST_FILE"
else
LOCUST_FILE="locustfile.py"
echo "Default Locust file: $LOCUST_FILE"
fi
}
do_exec() {
sleep $INITIAL_DELAY
# check if host is running
STATUS=$(curl -s -o /dev/null -w "%{http_code}" ${TARGET_HOST})
if [ $STATUS -ne 200 ]; then
echo "${TARGET_HOST} is not accessible"
exit 1
fi
echo "Will run $LOCUST_FILE against $TARGET_HOST. Spawning $CLIENTS clients and $REQUESTS total requests."
locust --host=http://$TARGET_HOST -f $LOCUST_FILE --clients=$CLIENTS --hatch-rate=5 --num-request=$REQUESTS --no-web --only-summary
echo "done"
}
do_usage() {
cat >&2 <<EOF
Usage:
${SCRIPT_NAME} [ hostname ] OPTIONS
Options:
-d Delay before starting
-h Target host url, e.g. http://localhost/
-c Number of clients (default 2)
-r Number of requests (default 10)
Description:
Runs a Locust load simulation against specified host.
EOF
exit 1
}
while getopts ":d:h:c:r:" o; do
case "${o}" in
d)
INITIAL_DELAY=${OPTARG}
#echo $INITIAL_DELAY
;;
h)
TARGET_HOST=${OPTARG}
#echo $TARGET_HOST
;;
c)
CLIENTS=${OPTARG:-2}
#echo $CLIENTS
;;
r)
REQUESTS=${OPTARG:-10}
#echo $REQUESTS
;;
*)
do_usage
;;
esac
done
do_check
do_exec