114 lines
2.8 KiB
Bash
Executable file
114 lines
2.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
JMX_FILE="./stitcher-benchmark.jmx"
|
|
JMETER_CMD="jmeter"
|
|
DEFAULT_THREADS=10
|
|
DEFAULT_LOOPS=10
|
|
|
|
APP_NAME=""
|
|
TARGET_URL=""
|
|
THREADS=$DEFAULT_THREADS
|
|
LOOPS=$DEFAULT_LOOPS
|
|
|
|
show_help() {
|
|
echo "Usage: $0 -u <AppName> -H <TargetURL> [-t <Threads>] [-l <Loops>]"
|
|
echo ""
|
|
echo "Runs a JMeter benchmark test with specified parameters."
|
|
echo ""
|
|
echo "Required Flags:"
|
|
echo " -o, --output The name of the app or user for organizing results."
|
|
echo " -H, --host The target URL or IP address for the test (e.g., 10.250.22.29)."
|
|
echo ""
|
|
echo "Optional Flags:"
|
|
echo " -t, --threads Number of concurrent threads (users). Default: ${DEFAULT_THREADS}."
|
|
echo " -l, --loops Number of loops each thread will execute. Default: ${DEFAULT_LOOPS}."
|
|
echo " -h, --help Display this help message and exit."
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
key="$1"
|
|
case $key in
|
|
-o|--output)
|
|
APP_NAME="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-H|--host)
|
|
TARGET_URL="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-t|--threads)
|
|
THREADS="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-l|--loops)
|
|
LOOPS="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$APP_NAME" ] || [ -z "$TARGET_URL" ]; then
|
|
echo "ERROR: Missing required arguments."
|
|
echo ""
|
|
show_help
|
|
exit 1
|
|
fi
|
|
|
|
# --- Define Output Structure ---
|
|
MAIN_OUTPUT_DIR="./${APP_NAME}"
|
|
RESULT_CSV="${MAIN_OUTPUT_DIR}/${APP_NAME}_benchmark.csv"
|
|
RESULT_DASHBOARD="${MAIN_OUTPUT_DIR}/${APP_NAME}_dashboard"
|
|
JMETER_LOG_FILE="${MAIN_OUTPUT_DIR}/${APP_NAME}_jmeter.log"
|
|
|
|
echo "--- Preparing for test run: '$APP_NAME' ---"
|
|
mkdir -p "$MAIN_OUTPUT_DIR"
|
|
echo "Output will be saved in: $MAIN_OUTPUT_DIR"
|
|
|
|
echo "Cleaning up previous results..."
|
|
rm -f "$RESULT_CSV"
|
|
rm -rf "$RESULT_DASHBOARD"
|
|
rm -f "$JMETER_LOG_FILE"
|
|
echo "Cleanup complete."
|
|
|
|
echo ""
|
|
echo "--- Starting JMeter Benchmark ---"
|
|
echo " Target Host: $TARGET_URL"
|
|
echo " Concurrency: $THREADS threads"
|
|
echo " Iterations: $LOOPS loops per thread"
|
|
echo " Total Requests: $((THREADS * LOOPS))"
|
|
echo "---------------------------------"
|
|
|
|
$JMETER_CMD -n \
|
|
-t "$JMX_FILE" \
|
|
-l "$RESULT_CSV" \
|
|
-e -o "$RESULT_DASHBOARD" \
|
|
-j "$JMETER_LOG_FILE" \
|
|
-Jthreads="$THREADS" \
|
|
-Jloops="$LOOPS" \
|
|
-Jurl="$TARGET_URL"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo ""
|
|
echo "--- Benchmark Finished Successfully ---"
|
|
echo "The HTML report is available here:"
|
|
echo "file://$PWD/${RESULT_DASHBOARD}/index.html"
|
|
echo "---------------------------------------"
|
|
else
|
|
echo ""
|
|
echo "--- JMeter Finished with an Error ---"
|
|
echo "Check the log file for details: ${JMETER_LOG_FILE}"
|
|
echo "-------------------------------------"
|
|
fi
|