Saturday, August 10, 2013

Understanding auto scaling policy and CloudWatch alarms

Taking a look at an example auto scaling policy you can see that there is nothing to indicate when to scale up or down:
as-put-scaling-policy reachforce-scale-in-policy --auto-scaling-group reachforce-as-grp --adjustment=20 --type PercentChangeInCapacity
ARM - arn:aws:autoscaling:us-west-2:649163059618:scalingPolicy:d9a6780b-3319-4b00-98f1-e98dcfc68d82:autoScalingGroupName/reachforce-as-grp:policyName/reachforce-scale-in-policy

This policy does specify the "how"; scale 20% (adjustment) for a percentage change in capacity (how much you will scale up or down as a percentage of current capacity).

This is controlled using a CloudWatch metrics alarm.  
mon-put-metric-alarm --alarm-name AddCapacity --metric-name CPUUtilization --namespace "AWS/EC2" --statistic "Average" --evaluation-periods 6 --period 120 --threshold 80 --comparison-operator GreaterThanOrEqualToThreshold --dimensions "AutoScalingGroupName=reachforce-as-grp"  --alarm-actions arn:aws:autoscaling:us-west-2:649163059618:scalingPolicy:69270ce4-3350-48f4-9d6f-71bc64225554:autoScalingGroupName/reachforce-as-grp:policyName/reachforce-scale-out-policy

This command ties a cloudwatch metrics to the auto scaling policy above.  The parameters that define the what and when are:
1. What : -metric-name CPUUtilization -- : CPU utilization is the most common metric used.  You also see the threshold of 80% for the CPU utilization.  So, when the CPU is on average over 80%.
2. When: Controlled by the evaluation periods, period and threshold:
A. Evaluation periods : The number of times to check if the alarm metric has been meet before triggering the alarm/policy.
B. Period : Is the length of time to check the alarm metric (in this case CPU utilization).  This value is in seconds.  So, in this case for 2 minutes.

If you look in the AWS CloudWatch console, you see this metrics threshold defined as:
the value is  80 for 12 minutes. This is because you specified 120 seconds for the periods
and 6 for the number of periods.
You also specify evaluation periods and period on the scale down alarm so you don't get constant
scaling up and down of the auto scaling group.

No comments:

Post a Comment