Skip to content

Commit

Permalink
Merge pull request #7 from aservo/feature/entrypoint-improvements
Browse files Browse the repository at this point in the history
Entrypoint: Define JVM_ARGS when unset, print logs, improve output
  • Loading branch information
pathob authored May 24, 2023
2 parents e865bd2 + 38ddf66 commit dd0cce5
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,57 @@
# Basically runs jmeter, assuming the PATH is set to point to JMeter bin-dir (see Dockerfile)
#
# This script expects the standard JMeter command parameters.
# See https://jmeter.apache.org/usermanual/get-started.html#non_gui for details

set -e
set -o pipefail

freeMem=`awk '/MemFree/ { print int($2/1024) }' /proc/meminfo`
s=$(($freeMem/10*8))
x=$(($freeMem/10*8))
n=$(($freeMem/10*2))
export JVM_ARGS="-Xmn${n}m -Xms${s}m -Xmx${x}m"
# Store arguments to pass to JMeter in a JMETER_ARGS variable
JMETER_ARGS=$@

echo "START Running Jmeter on `date`"
# If JVM_ARGS environment variable is not set, set it to default value
if [ -z "${JVM_ARGS}" ]
then
MEM_FREE=`awk '/MemFree/ { print int($2/1024) }' /proc/meminfo`
MEM_N=$((${MEM_FREE}/10*2))
MEM_S=$((${MEM_FREE}/10*8))
MEM_X=$((${MEM_FREE}/10*8))
JVM_ARGS="-Xmn${MEM_N}m -Xms${MEM_S}m -Xmx${MEM_X}m"
export JVM_ARGS
fi

echo "JMETER_ARGS=${JMETER_ARGS}"
echo "JVM_ARGS=${JVM_ARGS}"
echo "JMeter args=$@"
echo ""
echo "START Running JMeter on `date`"
echo ""

# Pass JMETER_ARGS and redirect stdout and stderr to file to check whether the test was successful
jmeter ${JMETER_ARGS} 2>&1 | tee output.log

echo ""
echo "END Running JMeter on `date`"
echo ""

# If JMETER_ARGS contain '--' option (like for version or help), exit without checking the output
if [[ ${JMETER_ARGS} == *--* ]]
then
exit 0
fi

# If JMETER_ARGS contain '-j' option, output the log file passed to '-j' option, else output the default log file
echo "JMeter log file:"
if [[ ${JMETER_ARGS} == *-j* ]]
then
cat $(echo ${JMETER_ARGS} | sed s/.*-j// | cut -d " " -f 2)
else
cat jmeter.log
fi

# Pass JMeter arguments and redirect stdout and err to file for checking whether or not the test was successful
jmeter $@ 2>&1 | tee jmeter-output
echo "END Running Jmeter on `date`"
echo ""

# Evaluate jmeter process output
if grep -q -E 'Err:.+[1-9]\W\(' jmeter-output
# Evaluate JMeter process output
if grep -q -E 'Err:.+[1-9]\W\(' output.log
then
echo "RESULT: test failed :-( - return code 1"
exit 1
Expand Down

0 comments on commit dd0cce5

Please sign in to comment.