Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6a7077

Browse files
committed
Merge pull request antonbabenko#3 from antonbabenko/feature/asg
Feature: feature/asg
2 parents f763789 + 90eafac commit f6a7077

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

projects/heavy/asg_policy.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Don't forget to remove desired_capacity on asg
2+
resource "aws_autoscaling_policy" "heavy-out" {
3+
name = "heavy-out-asg-policy"
4+
scaling_adjustment = 1
5+
adjustment_type = "ChangeInCapacity"
6+
cooldown = 10
7+
autoscaling_group_name = "${aws_autoscaling_group.heavy.name}"
8+
}
9+
10+
resource "aws_autoscaling_policy" "heavy-in" {
11+
name = "heavy-in-asg-policy"
12+
scaling_adjustment = -1
13+
adjustment_type = "ChangeInCapacity"
14+
cooldown = 10
15+
autoscaling_group_name = "${aws_autoscaling_group.heavy.name}"
16+
}
17+
18+
resource "aws_cloudwatch_metric_alarm" "heavy_asg_cpu_usage_is_very_high" {
19+
alarm_name = "heavy-asg-cpu-usage-is-very-high"
20+
comparison_operator = "GreaterThanOrEqualToThreshold"
21+
evaluation_periods = 1
22+
metric_name = "CPUUtilization"
23+
namespace = "AWS/EC2"
24+
period = 60
25+
statistic = "Average"
26+
threshold = 80
27+
dimensions {
28+
AutoScalingGroupName = "${aws_autoscaling_group.heavy.name}"
29+
}
30+
alarm_description = "This metric monitors EC2 CPU utilization"
31+
alarm_actions = ["${aws_autoscaling_policy.heavy-out.arn}"]
32+
}
33+
34+
resource "aws_cloudwatch_metric_alarm" "heavy_asg_cpu_usage_is_very_low" {
35+
alarm_name = "heavy-asg-cpu-usage-is-very-low"
36+
comparison_operator = "LessThanOrEqualToThreshold"
37+
evaluation_periods = 1
38+
metric_name = "CPUUtilization"
39+
namespace = "AWS/EC2"
40+
period = 60
41+
statistic = "Average"
42+
threshold = 40
43+
dimensions {
44+
AutoScalingGroupName = "${aws_autoscaling_group.heavy.name}"
45+
}
46+
alarm_description = "This metric monitors EC2 CPU utilization"
47+
alarm_actions = ["${aws_autoscaling_policy.heavy-in.arn}"]
48+
}

projects/heavy/web.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ resource "aws_elb" "heavy" {
147147
health_check {
148148
healthy_threshold = 2
149149
unhealthy_threshold = 2
150-
interval = 15
150+
interval = 7
151151
timeout = 5
152152
target = "HTTP:80/"
153153
}

0 commit comments

Comments
 (0)