Skip to content

Instantly share code, notes, and snippets.

@claydanford
Created June 5, 2019 20:47
Show Gist options
  • Save claydanford/8230e09a00d8d3fd9a0d035c44c24ee8 to your computer and use it in GitHub Desktop.
Save claydanford/8230e09a00d8d3fd9a0d035c44c24ee8 to your computer and use it in GitHub Desktop.
Jenkins master node polls for busy executors and scales.
#!/bin/bash
for i in {1..3};
do
AGENT_ASG="$(aws autoscaling describe-auto-scaling-groups --region ${aws_region} | jq -r '.AutoScalingGroups[] | select(.AutoScalingGroupName | startswith("${application}-agent-")) | .AutoScalingGroupName')"
BUILD_ACTIVE_QUEUE_VALUE1="$(curl -s -m 60 -u 'admin:APIKEY' 'http://localhost:8080/computer/api/json' | jq -r '.busyExecutors')"
BUILD_ACTIVE_QUEUE_VALUE2="$(curl -s -m 60 -u 'admin:APIKEY' 'http://localhost:8080/jqs-monitoring/api/json' | jq -r '.buildQueue.numberOfJobs')"
BUILD_ACTIVE_QUEUE_VALUE=$(( $BUILD_ACTIVE_QUEUE_VALUE1 + $BUILD_ACTIVE_QUEUE_VALUE2 ))
TOTAL_EXECUTORS="$(curl -s -m 60 -u 'admin:APIKEY' 'http://localhost:8080/computer/api/json' | jq -r '.totalExecutors')"
AVAILABLE_EXECUTORS=$(( $TOTAL_EXECUTORS - $BUILD_ACTIVE_QUEUE_VALUE ))
aws cloudwatch put-metric-data --namespace JenkinsBuildActiveQueue --metric-name AvailableExecutors --value $AVAILABLE_EXECUTORS --dimensions AutoScalingGroupName=$AGENT_ASG --unit Count --region ${aws_region}
sleep 15
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment