I am setting up auto scaling based on memory consumed by the particular instance. I went through the link posted at awsforums. I was able to set my metrics and using the bash script given and with the same variables.
In figuring out how to set auto scaling based on those metrics, I came to know about the bunch of bash scripts at google project hosting site. I am not able to set the metrics.
How could I move further?
Once you have the memory metrics logged to Cloudwatch, you simply need to setup autoscaling as you would for any existing metric.
Firstly, as with all the AWS command line tools, you need to set (export) either:
Next you run the following three commands, modifying them as per your needs (these are just run from the command line - once - not from cron).
Create the launch config: You need to pass an image and instance type at very least, additional parameters are optional, but probably a good idea.
For example:
Create the autoscaling group: Here we define the parameters for scaling - where the instances will be launched, the limits on the number of instances, and associate the group with the config we created.
For example:
(You can also specify a --desired-capacity which is the number of instances to start with, if it is different than the min-size)
Create a policy to scale with: Here we define the action that will be performed when an alarm is triggered and associate the policy with a specific autoscaling group. Create one policy for scaling up, and one for scaling down.
This command outputs a ARN that will be needed in order to associate the policy with a cloudwatch alarm - note down the ARN. Each command will return a different ARN - i.e. you will have 2 ARNs - remember which one is for which policy.
For example:
Scale-up:
Scale-down:
Example return:
Create a Cloudwatch alarm for each case: We need to use our collected data to trigger an alarm under specific circumstances, and then have that alarm execute the appropriate scaling policy. You will need 2 alarms - one for the upper threshold, and one for the lower threshold.
For example:
Upper threshold:
Lower threshold:
In the above example, we are using the metric 'UsedMemoryPercent' (from the forum script) and are looking at the 'average over 60 seconds'. For the first alarm, if that average exceeds 85% for 4 consecutive samples (i.e. 4 minutes) we will trigger the alarm (and execute the action), For the second alarm, we look for 'less than 60%'.
Good references include:
Run the command with
--help
to see the details of the parameters.You can make use of the template script I provided here because it's the same way I do the auto-scaling from the EC2 instance itself. I only have to add the specific commands to auto-scale right after the lines
<SEND_INFORMATION_GATHERED_BY_EMAIL_HERE>
because I also want to know what causes what. But make sure that you have the necessary AWS provided tools inside your EC2 instance.Good luck!