├── OSSMETADATA ├── README.textile └── scripts ├── scale-down.sh └── scale-up.sh /OSSMETADATA: -------------------------------------------------------------------------------- 1 | osslifecycle=archived 2 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | Tools for using auto scaling and documentation related to best practices. -------------------------------------------------------------------------------- /scripts/scale-down.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (C) 2011 Netflix 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # scale-down.sh 17 | # Justin Becker 18 | # Creates AWS policies and alarms neccessary to enable auto-scaling 19 | # Optionally can create the alarm to send an email notification on 20 | # an auto-scaling event. 21 | # 22 | # Also creates a rollback.sh script to delete all the policies and 23 | # alarms created. 24 | 25 | if [ $# -lt 8 ]; then 26 | echo "usage: scale-up asgname percentage namespace metric threshold period occurrences cooldown [topic-arn]" 27 | exit 28 | fi 29 | 30 | # COOLDOWN : 31 | # PERCENTAGE : Number of machines to scale by 32 | # NAMESPACE : Cloudwatch namespace. Example, "AWS/EC2" 33 | # METRIC : Cloudwatch metric. Example, "CPUUtilization" 34 | # THRESHOLD : Metric threshold. Example, 60 -- CPU greater than 60% 35 | # PERIOD : Time in seconds, must be greater than 60 36 | # OCCURRENCES : Number of occurrences of metric crossing threshold in period 37 | # COOLDOWN : Amount of time to wait before policy is active again, allows a time-buffer before firing another capacity event. 38 | 39 | ASG=$1 40 | ROLLBACK="rollback-"$ASG"-scale-down.sh" 41 | PERCENTAGE=$2 42 | NAMESPACE=$3 43 | METRIC=$4 44 | THRESHOLD=$5 45 | PERIOD=$6 46 | OCCURRENCES=$7 47 | COOLDOWN=$8 48 | 49 | POLICY_NAME=scale-down-$ASG-$PERCENTAGE-$COOLDOWN 50 | POLICY_ALARM_NAME=scale-down-alarm-$ASG-$METRIC-$THRESHOLD 51 | 52 | echo "Creating policy: "$POLICY_NAME 53 | ARN_POLICY=`as-put-scaling-policy $POLICY_NAME --auto-scaling-group $ASG --adjustment=-$PERCENTAGE --type PercentChangeInCapacity --cooldown $COOLDOWN` 54 | echo "Policy created: "$ARN_POLICY 55 | echo "Creating alarm: "$POLICY_ALARM_NAME 56 | # Check if topic-arn passed in, if so, add as an action 57 | if [ $# -eq 9 ]; then 58 | TOPIC_ARN=$9 59 | ARN_POLICY_ALARM=`mon-put-metric-alarm $POLICY_ALARM_NAME --dimensions "AutoScalingGroupName=$ASG" --comparison-operator LessThanThreshold --evaluation-periods $OCCURRENCES --metric-name $METRIC --namespace $NAMESPACE --period $PERIOD --statistic Average --threshold $THRESHOLD --alarm-actions $ARN_POLICY,$TOPIC_ARN` 60 | else 61 | ARN_POLICY_ALARM=`mon-put-metric-alarm $POLICY_ALARM_NAME --dimensions "AutoScalingGroupName=$ASG" --comparison-operator LessThanThreshold --evaluation-periods $OCCURRENCES --metric-name $METRIC --namespace $NAMESPACE --period $PERIOD --statistic Average --threshold $THRESHOLD --alarm-actions $ARN_POLICY` 62 | fi 63 | echo "Alarm created: "$POLICY_ALARM_NAME 64 | echo "Creating rollback file: "$ROLLBACK 65 | 66 | # ROLLBACK DATA 67 | echo "#!/bin/sh" > $ROLLBACK 68 | echo "echo 'Deleting alarm: '"$POLICY_ALARM_NAME >> $ROLLBACK 69 | echo "mon-delete-alarms "$POLICY_ALARM_NAME >> $ROLLBACK 70 | 71 | # ROLLBACK DATA 72 | echo "echo 'Deleting policy: '"$POLICY_NAME >> $ROLLBACK 73 | echo "as-delete-policy "$ARN_POLICY >> $ROLLBACK -------------------------------------------------------------------------------- /scripts/scale-up.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (C) 2011 Netflix 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # scale-up.sh 17 | # Justin Becker 18 | # Creates AWS policies and alarms neccessary to enable auto-scaling 19 | # Optionally can create the alarm to send an email notification on 20 | # an auto-scaling event. 21 | # 22 | # Also creates a rollback.sh script to delete all the policies and 23 | # alarms created. 24 | 25 | if [ $# -lt 8 ]; then 26 | echo "usage: scale-up asgname percentage namespace metric threshold period occurrences cooldown [topic-arn]" 27 | exit 28 | fi 29 | 30 | # COOLDOWN : 31 | # PERCENTAGE : Number of machines to scale by 32 | # NAMESPACE : Cloudwatch namespace. Example, "AWS/EC2" 33 | # METRIC : Cloudwatch metric. Example, "CPUUtilization" 34 | # THRESHOLD : Metric threshold. Example, 60 -- CPU greater than 60% 35 | # PERIOD : Time in seconds, must be greater than 60 36 | # OCCURRENCES : Number of occurrences of metric crossing threshold in period 37 | # COOLDOWN : Amount of time to wait before policy is active again, allows a time-buffer before firing another capacity event. 38 | 39 | ASG=$1 40 | ROLLBACK="rollback-"$ASG"-scale-up.sh" 41 | PERCENTAGE=$2 42 | NAMESPACE=$3 43 | METRIC=$4 44 | THRESHOLD=$5 45 | PERIOD=$6 46 | OCCURRENCES=$7 47 | COOLDOWN=$8 48 | 49 | POLICY_NAME=scale-up-$ASG-$PERCENTAGE-$COOLDOWN 50 | POLICY_ALARM_NAME=scale-up-alarm-$ASG-$METRIC-$THRESHOLD 51 | 52 | echo "Creating policy: "$POLICY_NAME 53 | ARN_POLICY=`as-put-scaling-policy $POLICY_NAME --auto-scaling-group $ASG --adjustment=$PERCENTAGE --type PercentChangeInCapacity --cooldown $COOLDOWN` 54 | echo "Policy created: "$ARN_POLICY 55 | echo "Creating alarm: "$POLICY_ALARM_NAME 56 | # Check if topic-arn passed in, if so, add as an action 57 | if [ $# -eq 9 ]; then 58 | TOPIC_ARN=$9 59 | ARN_POLICY_ALARM=`mon-put-metric-alarm $POLICY_ALARM_NAME --dimensions "AutoScalingGroupName=$ASG" --comparison-operator GreaterThanThreshold --evaluation-periods $OCCURRENCES --metric-name $METRIC --namespace $NAMESPACE --period $PERIOD --statistic Average --threshold $THRESHOLD --alarm-actions $ARN_POLICY,$TOPIC_ARN` 60 | else 61 | ARN_POLICY_ALARM=`mon-put-metric-alarm $POLICY_ALARM_NAME --dimensions "AutoScalingGroupName=$ASG" --comparison-operator GreaterThanThreshold --evaluation-periods $OCCURRENCES --metric-name $METRIC --namespace $NAMESPACE --period $PERIOD --statistic Average --threshold $THRESHOLD --alarm-actions $ARN_POLICY` 62 | fi 63 | echo "Alarm created: "$POLICY_ALARM_NAME 64 | echo "Creating rollback file: "$ROLLBACK 65 | 66 | # ROLLBACK DATA 67 | echo "#!/bin/sh" > $ROLLBACK 68 | echo "echo 'Deleting alarm: '"$POLICY_ALARM_NAME >> $ROLLBACK 69 | echo "mon-delete-alarms "$POLICY_ALARM_NAME >> $ROLLBACK 70 | 71 | # ROLLBACK DATA 72 | echo "echo 'Deleting policy: '"$POLICY_NAME >> $ROLLBACK 73 | echo "as-delete-policy "$ARN_POLICY >> $ROLLBACK 74 | --------------------------------------------------------------------------------