scale.tf
2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
## Autscale policy
resource "aws_autoscaling_policy" "scale_in_xpdays" {
name = "autoscale_in_policy_xpdays-${var.instance_suffix[count.index]}"
adjustment_type = "ChangeInCapacity"
policy_type = "StepScaling"
estimated_instance_warmup = 35
autoscaling_group_name = "${element(aws_autoscaling_group.asg-xpdays.*.name, count.index)}"
step_adjustment {
scaling_adjustment = 0
metric_interval_upper_bound = 1
}
step_adjustment {
scaling_adjustment = 1
metric_interval_lower_bound = 1
}
count = "${length(var.instance_suffix)}"
}
## Autoscale Alarm Metrics
resource "aws_cloudwatch_metric_alarm" "metric_alarm_cpu_high_xpdays" {
alarm_name = "metric_alarm_high_cpu_xpdays_${var.instance_suffix[count.index]}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Average"
threshold = "79"
dimensions {
AutoScalingGroupName = "${element(aws_autoscaling_group.asg-xpdays.*.name, count.index)}"
}
alarm_description = "This metric monitors xpdays group cpu utilization"
alarm_actions = ["${element(aws_autoscaling_policy.scale_in_xpdays.*.arn, count.index)}"]
count = "${length(var.instance_suffix)}"
}
resource "aws_autoscaling_policy" "scale_out_xpdays" {
name = "autoscale_out_policy_xpdays-${var.instance_suffix[count.index]}"
adjustment_type = "ChangeInCapacity"
policy_type = "StepScaling"
estimated_instance_warmup = 35
autoscaling_group_name = "${element(aws_autoscaling_group.asg-xpdays.*.name, count.index)}"
step_adjustment {
scaling_adjustment = -1 # remove one node
# scaling_adjustment = 0 # disable downscale
metric_interval_upper_bound = 1
}
step_adjustment {
scaling_adjustment = 0
metric_interval_lower_bound = 1
}
count = "${length(var.instance_suffix)}"
}
resource "aws_cloudwatch_metric_alarm" "metric_alarm_cpu_low_xpdays" {
alarm_name = "metric_alarm_low_cpu_xpdays_${var.instance_suffix[count.index]}"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Average"
threshold = "39"
dimensions {
AutoScalingGroupName = "${element(aws_autoscaling_group.asg-xpdays.*.name, count.index)}"
}
alarm_description = "This metric monitors xpdays group cpu utilization"
alarm_actions = ["${element(aws_autoscaling_policy.scale_out_xpdays.*.arn, count.index)}"]
count = "${length(var.instance_suffix)}"
}
## Print Output
output "xpdays_elb_dns_name" {
value = "${module.m-elb-xpdays.elb_dns_name}"
}