Skip to content

Commit

Permalink
Merge pull request #34 from smithmicro/feature-33
Browse files Browse the repository at this point in the history
Supporting JMeter 5.0
  • Loading branch information
dsperling authored Jan 23, 2019
2 parents f7cef00 + 7c1aad5 commit 09ead8d
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 36 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ The following required and optional environment variables are supported:
|SECURITY_GROUP|Yes|None|AWS Secuirty group that allows ports 22,1099,50000,51000/tcp and 4445/udp from all ports (e.g. sg-12345678)|
|SUBNET_ID|Yes|None|One or more Subnets (comma separated) that are assigned to your VPC|
|VPC_ID||VPC assigned to SUBNET_ID|We dautomatically erive this from your SUBNET_ID|
|JMETER_VERSION||latest|smithmicro/lucy Image tag. See Docker Hub for [available versions](https://hub.docker.com/r/smithmicro/jmeter/tags/).|
|JMETER_VERSION||latest|smithmicro/jmeter Image tag. See Docker Hub for [available versions](https://hub.docker.com/r/smithmicro/jmeter/tags/).|
|INSTANCE_TYPE||t2.micro|To double your memory, pass `t2.small`|
|MEM_LIMIT||950m|If you are using t2.small, set MEM_LIMIT to `1995m`|
|JMETER_MEMORY||-Xms800m -Xmx800m|If you are using t2.small, set JMETER_MEMORY to `Xms1600m -Xmx1600m`|
|MINION_COUNT||2||
|PEM_PATH||/keys|This must match your Volume map. See Volume section above.|
|CLUSTER_NAME||JMeter|Name that appears in your AWS Cluster UI|
Expand Down
11 changes: 7 additions & 4 deletions aws-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ fi
if [ "$OWNER" == '' ]; then
OWNER=jmeter-ecs
fi
if [ "$AWS_REGION" == '' ]; then
AWS_REGION=$(aws configure get region)
fi

# keep the tags consistant so we can easily detect if a JMeter VPC already exists
VPC_TAGS="Key=Name,Value=JMeter-VPC Key=Owner,Value=$OWNER Key=Stack,Value=JMeter"
Expand All @@ -43,10 +46,10 @@ echo "Created VPC $VPC_ID"
# enable DNS hostnames
aws ec2 modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-hostnames --output text

# create a 2 subnets
SUBNET_ID1=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $SUBNET_CIDR_BLOCK1 \
# create 2 subnets
SUBNET_ID1=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $SUBNET_CIDR_BLOCK1 --availability-zone "$AWS_REGION"a \
--query 'Subnet.[SubnetId]' --output text | tr -d '\n')
SUBNET_ID2=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $SUBNET_CIDR_BLOCK2 \
SUBNET_ID2=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $SUBNET_CIDR_BLOCK2 --availability-zone "$AWS_REGION"b \
--query 'Subnet.[SubnetId]' --output text | tr -d '\n')
echo "Created Subnets $SUBNET_ID1,$SUBNET_ID2"

Expand Down Expand Up @@ -78,7 +81,7 @@ aws ec2 modify-subnet-attribute --subnet-id $SUBNET_ID2 --map-public-ip-on-launc
SG_ID=$(aws ec2 create-security-group --group-name "JMeter" --description "JMeter Security Group" --vpc-id $VPC_ID --output text | tr -d '\n')
echo "Created Security Group $SG_ID"

JMETER_IP_PERMISSIONS='[{"IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "tcp", "FromPort": 1099, "ToPort": 1099, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "udp", "FromPort": 4445, "ToPort": 4445, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "tcp", "FromPort": 50000, "ToPort": 50000, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "tcp", "FromPort": 51000, "ToPort": 51000, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]}]'
JMETER_IP_PERMISSIONS='[{"IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "tcp", "FromPort": 1099, "ToPort": 1099, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "udp", "FromPort": 4445, "ToPort": 4445, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "tcp", "FromPort": 50000, "ToPort": 50000, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]},{"IpProtocol": "tcp", "FromPort": 51000, "ToPort": 51999, "IpRanges": [{"CidrIp": "0.0.0.0/0"}]}]'
aws ec2 authorize-security-group-ingress --group-id $SG_ID --ip-permissions "$JMETER_IP_PERMISSIONS"

# tag all created resources
Expand Down
2 changes: 1 addition & 1 deletion jmeter/3.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV PLUGINMGR_VERSION 1.3
# overridable environment variables
ENV RESULTS_LOG results.jtl
ENV JMETER_FLAGS=
ENV JMETER_MEMORY -Xms800m -Xmx800m
ENV JMETER_MEMORY -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
ENV CUSTOM_PLUGIN_URL=

# Install the required tools for JMeter
Expand Down
2 changes: 1 addition & 1 deletion jmeter/3.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV PLUGINMGR_VERSION 1.3
# overridable environment variables
ENV RESULTS_LOG results.jtl
ENV JMETER_FLAGS=
ENV JMETER_MEMORY -Xms800m -Xmx800m
ENV JMETER_MEMORY -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
ENV CUSTOM_PLUGIN_URL=

# Install the required tools for JMeter
Expand Down
2 changes: 1 addition & 1 deletion jmeter/3.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV PLUGINMGR_VERSION 1.3
# overridable environment variables
ENV RESULTS_LOG results.jtl
ENV JMETER_FLAGS=
ENV JMETER_MEMORY -Xms800m -Xmx800m
ENV JMETER_MEMORY -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
ENV CUSTOM_PLUGIN_URL=

# Install the required tools for JMeter
Expand Down
2 changes: 1 addition & 1 deletion jmeter/3.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV PLUGINMGR_VERSION 1.3
# overridable environment variables
ENV RESULTS_LOG results.jtl
ENV JMETER_FLAGS=
ENV JMETER_MEMORY -Xms800m -Xmx800m
ENV JMETER_MEMORY -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
ENV CUSTOM_PLUGIN_URL=

# Install the required tools for JMeter
Expand Down
48 changes: 48 additions & 0 deletions jmeter/4.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM openjdk:8-alpine

LABEL maintainer="David Sperling <[email protected]>"

ENV JMETER_VERSION apache-jmeter-4.0
ENV JMETER_HOME /opt/$JMETER_VERSION
ENV PATH $PATH:$JMETER_HOME/bin
ENV CMDRUNNER_VERSION 2.2
ENV PLUGINMGR_VERSION 1.3

# overridable environment variables
ENV RESULTS_LOG results.jtl
ENV JMETER_FLAGS=
ENV CUSTOM_PLUGIN_URL=

# Install the required tools for JMeter
RUN apk add --update --no-cache \
curl \
openssh-client

WORKDIR /opt

# install JMeter and the JMeter Plugins Manager
RUN curl -O https://archive.apache.org/dist/jmeter/binaries/$JMETER_VERSION.tgz \
&& tar -xvf $JMETER_VERSION.tgz \
&& rm $JMETER_VERSION.tgz \
&& rm -rf $JMETER_VERSION/docs $JMETER_VERSION/printable_docs \
&& cd $JMETER_HOME/lib \
&& curl -O http://search.maven.org/remotecontent?filepath=kg/apc/cmdrunner/$CMDRUNNER_VERSION/cmdrunner-$CMDRUNNER_VERSION.jar \
&& cd $JMETER_HOME/lib/ext \
&& curl -O http://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-manager/$PLUGINMGR_VERSION/jmeter-plugins-manager-$PLUGINMGR_VERSION.jar \
&& java -cp jmeter-plugins-manager-$PLUGINMGR_VERSION.jar org.jmeterplugins.repository.PluginManagerCMDInstaller

# install all available plugins except for those that are deprecated
RUN PluginsManagerCMD.sh install-all-except jpgc-hadoop,jpgc-oauth \
&& sleep 2 \
&& PluginsManagerCMD.sh status

# copy our entrypoint
COPY entrypoint.sh /opt/jmeter/

WORKDIR /logs

EXPOSE 1099 50000 51000 4445/udp

# default command in the entrypoint is 'minion'
ENTRYPOINT ["/opt/jmeter/entrypoint.sh"]
CMD ["minion"]
76 changes: 76 additions & 0 deletions jmeter/4.0/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/sh
#
# Main entrypoint for our Docker image - runs Gru, Minions or other commands

# any .jmx file passed in the command line we act as 'Gru'
if [ ${1##*.} = 'jmx' ]; then

if [ "$MINION_HOSTS" = '' ]; then
echo "MINION_HOSTS must be specified - a command separated list of hostnames or IP addresses"
exit 1
fi
echo "Connecting to $MINION_HOSTS"

# AWS Public HOSTNAME API
echo "Detecting an AWS Environment"
PUBLIC_HOSTNAME=$(curl -s --max-time 5 http://169.254.169.254/latest/meta-data/public-hostname)

if [ "$PUBLIC_HOSTNAME" = '' ]; then
echo "Not running in AWS. Using Gru HOSTNAME $HOSTNAME"
else
HOSTNAME=$PUBLIC_HOSTNAME
echo "Using Gru AWS Public HOSTNAME $HOSTNAME"
fi
# empty the logs directory, or jmeter may fail
rm -rf /logs/report /logs/*.log /logs/*.jtl

# remove setting JAVA heap and use the RUN_IN_DOCKER variable
sed -i 's/-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m//' $JMETER_HOME/bin/jmeter
sed -i 's/# RUN_IN_DOCKER/RUN_IN_DOCKER/' $JMETER_HOME/bin/jmeter

# run jmeter in client (gru) mode
exec jmeter -n $JMETER_FLAGS \
-R $MINION_HOSTS \
-Dclient.rmi.localport=51000 \
-Dserver.rmi.ssl.disable=true \
-Djava.rmi.server.hostname=${PUBLIC_HOSTNAME} \
-l $RESULTS_LOG \
-t $1 \
-e -o /logs/report

fi

# act as a 'Minion'
if [ "$1" = 'minion' ]; then

# AWS Public HOSTNAME API
echo "Detecting an AWS Environment"
PUBLIC_HOSTNAME=$(curl -s --max-time 5 http://169.254.169.254/latest/meta-data/public-hostname)

if [ "$PUBLIC_HOSTNAME" = '' ]; then
echo "Not running in AWS. Using Minion HOSTNAME $HOSTNAME"
else
HOSTNAME=$PUBLIC_HOSTNAME
echo "Using Minion AWS Public HOSTNAME $HOSTNAME"
fi

# remove setting JAVA heap and use the RUN_IN_DOCKER variable
sed -i 's/-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m//' $JMETER_HOME/bin/jmeter
sed -i 's/# RUN_IN_DOCKER/RUN_IN_DOCKER/' $JMETER_HOME/bin/jmeter

# install custom plugin if requested
if [ "$CUSTOM_PLUGIN_URL" != '' ]; then
echo "Installing custom plugin $CUSTOM_PLUGIN_URL"
CUSTOM_PLUGIN_FILE="${CUSTOM_PLUGIN_URL##*/}"
curl -o $JMETER_HOME/lib/ext/$CUSTOM_PLUGIN_FILE $CUSTOM_PLUGIN_URL
fi

# run jmeter in server (minion) mode
exec jmeter-server -n \
-Dserver.rmi.localport=50000 \
-Dserver.rmi.ssl.disable=true \
-Djava.rmi.server.hostname=${HOSTNAME}

fi

exec "$@"
3 changes: 1 addition & 2 deletions jmeter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM openjdk:8-alpine

LABEL maintainer="David Sperling <[email protected]>"

ENV JMETER_VERSION apache-jmeter-4.0
ENV JMETER_VERSION apache-jmeter-5.0
ENV JMETER_HOME /opt/$JMETER_VERSION
ENV PATH $PATH:$JMETER_HOME/bin
ENV CMDRUNNER_VERSION 2.2
Expand All @@ -11,7 +11,6 @@ ENV PLUGINMGR_VERSION 1.3
# overridable environment variables
ENV RESULTS_LOG results.jtl
ENV JMETER_FLAGS=
ENV JMETER_MEMORY -Xms800m -Xmx800m
ENV CUSTOM_PLUGIN_URL=

# Install the required tools for JMeter
Expand Down
14 changes: 8 additions & 6 deletions jmeter/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ if [ ${1##*.} = 'jmx' ]; then
# empty the logs directory, or jmeter may fail
rm -rf /logs/report /logs/*.log /logs/*.jtl

# set JAVA HEAP
sed -i 's/-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m/'"$JMETER_MEMORY"'/' $JMETER_HOME/bin/jmeter

# remove setting JAVA heap and use the RUN_IN_DOCKER variable
sed -i 's/-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m//' $JMETER_HOME/bin/jmeter
sed -i 's/# RUN_IN_DOCKER/RUN_IN_DOCKER/' $JMETER_HOME/bin/jmeter

# run jmeter in client (gru) mode
exec jmeter -n $JMETER_FLAGS \
-R $MINION_HOSTS \
Expand All @@ -53,9 +54,10 @@ if [ "$1" = 'minion' ]; then
echo "Using Minion AWS Public HOSTNAME $HOSTNAME"
fi

# set JAVA HEAP
sed -i 's/-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m/'"$JMETER_MEMORY"'/' $JMETER_HOME/bin/jmeter

# remove setting JAVA heap and use the RUN_IN_DOCKER variable
sed -i 's/-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m//' $JMETER_HOME/bin/jmeter
sed -i 's/# RUN_IN_DOCKER/RUN_IN_DOCKER/' $JMETER_HOME/bin/jmeter

# install custom plugin if requested
if [ "$CUSTOM_PLUGIN_URL" != '' ]; then
echo "Installing custom plugin $CUSTOM_PLUGIN_URL"
Expand Down
2 changes: 1 addition & 1 deletion lucy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.7
FROM alpine:3.8

LABEL maintainer="David Sperling <[email protected]>"

Expand Down
39 changes: 22 additions & 17 deletions lucy/lucy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,29 @@ else
fi
echo "Gru at $GRU_HOST"

MINION_HOSTS=$(aws ec2 describe-instances --instance-ids $MINION_INSTANCE_IDS \
if [ "$MINION_INSTANCE_IDS" == '' ]; then
echo "Error - no Minion instance IDs found."
else
MINION_HOSTS=$(aws ec2 describe-instances --instance-ids $MINION_INSTANCE_IDS \
--query 'Reservations[*].Instances[*].[PrivateIpAddress]' --output text | tr '\n' ',')
echo "Minions at $MINION_HOSTS"
# uncomment if you want to pause Lucy to inspect Gru or a Minion
#read -p "Press enter to start Gru setup: "

# Step 6 - Run Gru with the specified JMX
echo "Copying $INPUT_JMX to Gru"
scp -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $INPUT_JMX ec2-user@${GRU_HOST}:/tmp

echo "Running Docker to start JMeter in Gru mode"
JMX_IN_COMTAINER=/plans/$(basename $INPUT_JMX)
ssh -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@${GRU_HOST} \
"docker run -p 1099:1099 -p 51000:51000 -v /tmp:/plans -v /logs:/logs --env MINION_HOSTS=$MINION_HOSTS smithmicro/jmeter:$JMETER_VERSION $JMX_IN_COMTAINER"

# Step 6 - Fetch the results from Gru
echo "Copying results from Gru"
scp -r -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@${GRU_HOST}:/logs/* /logs

echo "Minions at $MINION_HOSTS"
# uncomment if you want to pause Lucy to inspect Gru or a Minion
#read -p "Press enter to start Gru setup: "

# Step 6 - Run Gru with the specified JMX
echo "Copying $INPUT_JMX to Gru"
scp -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $INPUT_JMX ec2-user@${GRU_HOST}:/tmp

echo "Running Docker to start JMeter in Gru mode"
JMX_IN_COMTAINER=/plans/$(basename $INPUT_JMX)
ssh -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@${GRU_HOST} \
"docker run --network host -v /tmp:/plans -v /logs:/logs --env MINION_HOSTS=$MINION_HOSTS --env JMETER_FLAGS=$JMETER_FLAGS smithmicro/jmeter:$JMETER_VERSION $JMX_IN_COMTAINER"

# Step 6 - Fetch the results from Gru
echo "Copying results from Gru"
scp -r -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@${GRU_HOST}:/logs/* /logs
fi

# Step 7 - Delete the cluster
if [ "$RETAIN_CLUSTER" == '' ]; then
Expand Down

0 comments on commit 09ead8d

Please sign in to comment.