-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloudwatch.tf
37 lines (32 loc) · 1.24 KB
/
cloudwatch.tf
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
resource "aws_cloudwatch_metric_alarm" "up" {
alarm_name = "ASG Up"
alarm_description = "Scales up an instance when CPU utilization is greater than 30%"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1 #for test - 2 is the correct
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 60 #for test - 120 segundos is the correct
statistic = "Average"
threshold = 55 #for test - 80% is the correct
dimensions = {
"AutoScalingGroupName" = aws_autoscaling_group.this.name
}
actions_enabled = true
alarm_actions = [aws_autoscaling_policy.scaleup.arn]
}
resource "aws_cloudwatch_metric_alarm" "down" {
alarm_name = "ASG Down"
alarm_description = "Scales down an instance when CPU utilization is lesser than 40%"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = 1
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 60
statistic = "Average"
threshold = 30
dimensions = {
"AutoScalingGroupName" = aws_autoscaling_group.this.name
}
actions_enabled = true
alarm_actions = [aws_autoscaling_policy.scaledown.arn]
}