Skip to content

Instantly share code, notes, and snippets.

@tsabat
Created June 29, 2013 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsabat/5891535 to your computer and use it in GitHub Desktop.
Save tsabat/5891535 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x verbose
########################
# Create scaling policy
########################
AUTOSCALING_GROUP="app-autoscaling-group"
TYPE="ChangeInCapacity"
COOLDOWN=300
# Policy function
function add_policy(){
local RSLT=`as-put-scaling-policy \
--auto-scaling-group $AUTOSCALING_GROUP \
--name $POLICY_NAME \
"--adjustment=$ADJUSTMENT" \
--type $TYPE \
--cooldown $COOLDOWN`
echo $RSLT
}
echo "scale up policy"
POLICY_NAME="scale-up"
ADJUSTMENT=1
SCALE_UP=$(add_policy)
echo "scale down policy"
POLICY_NAME="scale-down"
ADJUSTMENT="-1"
SCALE_DOWN=$(add_policy)
########################
# Create scaling alarms
########################
METRIC_NAME="CPUUtilization"
NAMESPACE="AWS/EC2"
STATISTIC="Average"
PERIOD="60"
DIMENSIONS="AutoScalingGroupName=$AUTOSCALING_GROUP"
EVAL_PERIODS=3
UNIT="Percent"
function add_alarm(){
local RSLT=`mon-put-metric-alarm --alarm-name $ALARM_NAME \
--alarm-description $ALARM_DESC \
--metric-name $METRIC_NAME \
--namespace $NAMESPACE \
--statistic $STATISTIC \
--period $PERIOD \
--threshold $THRESHOLD \
--comparison-operator $COMPARISON_OPERATOR \
--dimensions $DIMENSIONS \
--evaluation-periods $EVAL_PERIODS \
--unit $UNIT \
--alarm-actions $ALARM_ACTION`
echo $RSLT
}
echo "adding scale up alarm"
ALARM_NAME="app-scale-up"
THRESHOLD=70
ALARM_DESC="Scale-up-at-$THRESHOLD-percent-load"
COMPARISON_OPERATOR="GreaterThanThreshold"
ALARM_ACTION=$SCALE_UP
add_alarm
echo "adding scale down alarm"
ALARM_NAME="app-scale-down"
THRESHOLD=15
ALARM_DESC="Scale-down-at-$THRESHOLD-percent-load"
COMPARISON_OPERATOR="LessThanThreshold"
ALARM_ACTION=$SCALE_DOWN
add_alarm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment