We use some basic CloudWatch alarms on our EC2 instances to perform notification via SNS of high CPU, etc. Is there a good way to automatically apply our standard alarm configuration to new EC2 instances spun up by an Auto Scaling Group?
We use some basic CloudWatch alarms on our EC2 instances to perform notification via SNS of high CPU, etc. Is there a good way to automatically apply our standard alarm configuration to new EC2 instances spun up by an Auto Scaling Group?
Many of the common CloudWatch metrics are also aggregated based on their Auto Scaling group name.
So you can create alarms based on the CPU metric of the Auto Scaling group. You won't see the individual instance's metrics, but you'll be able to work with maximums, minimums, averages, etc.
You can use totalcloud for automatic alarm creation. They recently released a similar solution. There is a free tier you can use.
There's nothing out of the box from AWS to facilitate this. You'd could wire up something ad-hoc using AWS Lambda to poll for new instances and add the alarms.
At Setfive, we actually just released Cloudwatch Autowatch which will add alarms automatically to EC2s. You could just run that on a cron job and it'll take care of adding alarms to new autoscale instances.
If you were using OpsWorks. You could write a Config recipe to Add CloudWatch Alarms to each created instance while it's being started up. Use the below to get the instance id from config recipe.
Recipe: require 'rubygems' require 'aws-sdk' require 'net/http'
metadata_endpoint = 'http://169.254.169.254/latest/meta-data/' instance_id = Net::HTTP.get( URI.parse( metadata_endpoint + 'instance-id' ) )
ec2 = AWS::EC2.new() instance = ec2.instances[instance_id]