From 12a09829fa14f2d5009bc5efa3b6146662acc3bd Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Fri, 27 Sep 2024 11:45:15 +0100 Subject: [PATCH] Initial commit --- README.md | 33 +++++++++++++++++++++++++++++++++ miniloadtester | 42 ++++++++++++++++++++++++++++++++++++++++++ routes.csv | 2 ++ send_requests.bash | 21 +++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 README.md create mode 100755 miniloadtester create mode 100644 routes.csv create mode 100755 send_requests.bash diff --git a/README.md b/README.md new file mode 100644 index 0000000..7739dfb --- /dev/null +++ b/README.md @@ -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. diff --git a/miniloadtester b/miniloadtester new file mode 100755 index 0000000..412d5bf --- /dev/null +++ b/miniloadtester @@ -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 diff --git a/routes.csv b/routes.csv new file mode 100644 index 0000000..93be6a5 --- /dev/null +++ b/routes.csv @@ -0,0 +1,2 @@ +google.com GET 60 +github.com GET 30 diff --git a/send_requests.bash b/send_requests.bash new file mode 100755 index 0000000..86f37b5 --- /dev/null +++ b/send_requests.bash @@ -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