diff options
Diffstat (limited to 'cloudwatch.tf')
-rw-r--r-- | cloudwatch.tf | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cloudwatch.tf b/cloudwatch.tf new file mode 100644 index 0000000..9a73918 --- /dev/null +++ b/cloudwatch.tf @@ -0,0 +1,45 @@ +resource "aws_cloudwatch_metric_alarm" "target_healthy_count" { + alarm_name = "ELB-target-healthy-count" + comparison_operator = "LessThanOrEqualToThreshold" + evaluation_periods = "1" + metric_name = "HealthyHostCount" + period = "60" + statistic = "Average" + threshold = "0" + + dimensions { + LoadBalancer = "${aws_elb.app_elb.id}" + } + + alarm_description = "Trigger an alert when elb has 1 or more unhealthy hosts" + + #alarm_actions = "Would point at sns here" + #ok_actions = "Would also point at sns" + treat_missing_data = "breaching" +} + +resource "aws_autoscaling_policy" "app_as_policy" { + name = "app_autoscaling_policy" + scaling_adjustment = 1 + adjustment_type = "ChangeInCapacity" + cooldown = 300 + autoscaling_group_name = "${aws_autoscaling_group.app_asg.name}" +} + +resource "aws_cloudwatch_metric_alarm" "app_asg_alarm" { + alarm_name = "app_asg_alarm" + comparison_operator = "GreaterThanOrEqualToThreshold" + evaluation_periods = "2" + metric_name = "CPUUtilization" + namespace = "AWS/EC2" + period = "120" + statistic = "Average" + threshold = "80" + + dimensions = { + AutoScalingGroupName = "${aws_autoscaling_group.app_asg.name}" + } + + alarm_description = "This metric monitors ec2 cpu utilization" + alarm_actions = ["${aws_autoscaling_policy.app_as_policy.arn}"] +} |