-
Notifications
You must be signed in to change notification settings - Fork 4
/
cloudwatch-manager.tf
99 lines (81 loc) · 3.35 KB
/
cloudwatch-manager.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
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
88
89
90
91
92
93
94
95
96
97
98
99
resource "aws_cloudwatch_metric_alarm" "manager_cpu_high" {
alarm_name = "${var.name}-tf-${var.environment}-manager-cpureservation-high"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Maximum"
threshold = "70"
dimensions {
AutoScalingGroupName = "${aws_autoscaling_group.swarm-manager.name}"
}
alarm_description = "Scale up if the cpu reservation is above 70% for 10 minutes"
alarm_actions = ["${aws_autoscaling_policy.swarm-manager-scale-up.arn}"]
lifecycle {
create_before_destroy = true
}
}
resource "aws_cloudwatch_metric_alarm" "manager_memory_high" {
alarm_name = "${var.name}-tf-${var.environment}-manager-memoryreservation-high"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryReservation"
namespace = "AWS/EC2"
period = "300"
statistic = "Maximum"
threshold = "70"
dimensions {
AutoScalingGroupName = "${aws_autoscaling_group.swarm-manager.name}"
}
alarm_description = "Scale up if the memory reservation is above 70% for 10 minutes"
alarm_actions = ["${aws_autoscaling_policy.swarm-manager-scale-up.arn}"]
lifecycle {
create_before_destroy = true
}
# This is required to make cloudwatch alarms creation sequential, AWS doesn't
# support modifying alarms concurrently.
depends_on = ["aws_cloudwatch_metric_alarm.manager_cpu_high"]
}
resource "aws_cloudwatch_metric_alarm" "manager_cpu_low" {
alarm_name = "${var.name}-tf-${var.environment}-manager-cpureservation-low"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Maximum"
threshold = "20"
dimensions {
AutoScalingGroupName = "${aws_autoscaling_group.swarm-manager.name}"
}
alarm_description = "Scale down if the cpu reservation is below 20% for 10 minutes"
alarm_actions = ["${aws_autoscaling_policy.swarm-manager-scale-down.arn}"]
lifecycle {
create_before_destroy = true
}
# This is required to make cloudwatch alarms creation sequential, AWS doesn't
# support modifying alarms concurrently.
depends_on = ["aws_cloudwatch_metric_alarm.manager_memory_high"]
}
resource "aws_cloudwatch_metric_alarm" "manager_memory_low" {
alarm_name = "${var.name}-tf-${var.environment}-manager-memoryreservation-low"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryReservation"
namespace = "AWS/EC2"
period = "300"
statistic = "Maximum"
threshold = "20"
dimensions {
AutoScalingGroupName = "${aws_autoscaling_group.swarm-manager.name}"
}
alarm_description = "Scale down if the memory reservation is below 20% for 10 minutes"
alarm_actions = ["${aws_autoscaling_policy.swarm-manager-scale-down.arn}"]
lifecycle {
create_before_destroy = true
}
# This is required to make cloudwatch alarms creation sequential, AWS doesn't
# support modifying alarms concurrently.
depends_on = ["aws_cloudwatch_metric_alarm.manager_cpu_low"]
}