Initial commit
This commit is contained in:
commit
12a09829fa
|
@ -0,0 +1,33 @@
|
|||
# miniloadtest
|
||||
|
||||
miniloadtest is a BASH script which reads a config file of space-separated values
|
||||
like the example below and makes a series of HTTP requests at the specified
|
||||
frequency to allow you to monitor the load this places on your servers.
|
||||
|
||||
## Example
|
||||
|
||||
Configuration file:
|
||||
```csv
|
||||
google.com POST 60 {"some":"json","data":0}
|
||||
github.com GET 30
|
||||
```
|
||||
|
||||
```bash
|
||||
miniloadtester CONFIG_FILE
|
||||
```
|
||||
|
||||
To increase the rate by a given factor (e.g. ×2, here):
|
||||
```bash
|
||||
miniloadtester CONFIG_FILE 2
|
||||
```
|
||||
|
||||
## On the server
|
||||
|
||||
An easy way to monitor the load on your server and write it to a file every second:
|
||||
```bash
|
||||
until false ; do echo $(date +"%T") $[100-$(vmstat 1 2|tail -1|awk '{print $15}')]"%" >>load.txt ; sleep 1 ; done
|
||||
```
|
||||
|
||||
# Requirements
|
||||
|
||||
curl and GNU Parallel.
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
################################################################
|
||||
# miniloadtester
|
||||
################################################################
|
||||
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
|
||||
|
||||
main() {
|
||||
echo "Sending requests. Send interrupt to quit."
|
||||
cat $CONFIG_FILE | parallel --ungroup ./send_requests.bash $RATE_CHANGE_FACTOR
|
||||
}
|
||||
|
||||
if ! command -v "curl" 2>&1 >/dev/null
|
||||
then
|
||||
echo "Error: this script requires curl."
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v "parallel" 2>&1 >/dev/null
|
||||
then
|
||||
echo "Error: this script requires parallel."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
echo "Error: No configuration file specified."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CONFIG_FILE=$1
|
||||
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
RATE_CHANGE_FACTOR=1
|
||||
else
|
||||
RATE_CHANGE_FACTOR=$2
|
||||
fi
|
||||
|
||||
main
|
|
@ -0,0 +1,2 @@
|
|||
google.com GET 60
|
||||
github.com GET 30
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
|
||||
|
||||
RATE_CHANGE_FACTOR=$1
|
||||
IFS=" " read -r -a OPTS <<< $2
|
||||
URL=${OPTS[0]}; METHOD=${OPTS[1]}; RATE=${OPTS[2]}; BODY=${OPTS[3]}
|
||||
SLEEP_TIME=$(expr 60 / $RATE / $RATE_CHANGE_FACTOR)
|
||||
|
||||
until false
|
||||
do
|
||||
curl --header "Content-Type: application/json" \
|
||||
--data $BODY \
|
||||
-X $METHOD \
|
||||
-s $URL \
|
||||
-o /dev/null
|
||||
printf '%s' "."
|
||||
sleep $SLEEP_TIME
|
||||
done
|
Loading…
Reference in New Issue