This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
forked from Kgirthofer/ecs_cluster_terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudwatch.tf
96 lines (80 loc) · 3.97 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
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
#
# CloudWatch resources
#
resource "aws_autoscaling_policy" "container_instance_scale_up" {
name = "asgScalingPolicy${var.environment}${var.project}ClusterScaleUp"
scaling_adjustment = 3
adjustment_type = "ChangeInCapacity"
cooldown = "${var.scale_up_cooldown_seconds}"
autoscaling_group_name = "${aws_autoscaling_group.container_instance.name}"
}
resource "aws_autoscaling_policy" "container_instance_scale_down" {
name = "asgScalingPolicy${var.environment}${var.project}ClusterScaleDown"
scaling_adjustment = -1
adjustment_type = "ChangeInCapacity"
cooldown = "${var.scale_down_cooldown_seconds}"
autoscaling_group_name = "${aws_autoscaling_group.container_instance.name}"
}
resource "aws_cloudwatch_metric_alarm" "container_instance_high_cpu" {
alarm_name = "alarm${var.environment}${var.project}ClusterCPUReservationHigh"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "${var.high_cpu_evaluation_periods}"
metric_name = "CPUReservation"
namespace = "AWS/ECS"
period = "${var.high_cpu_period_seconds}"
statistic = "Maximum"
threshold = "${var.high_cpu_threshold_percent}"
dimensions = {
ClusterName = "${aws_ecs_cluster.container_instance.name}"
}
alarm_description = "Scale up if CPUReservation is above N% for N duration"
alarm_actions = ["${aws_autoscaling_policy.container_instance_scale_up.arn}"]
}
resource "aws_cloudwatch_metric_alarm" "container_instance_low_cpu" {
alarm_name = "alarm${var.environment}${var.project}ClusterCPUReservationLow"
comparison_operator = "LessThanThreshold"
evaluation_periods = "${var.low_cpu_evaluation_periods}"
metric_name = "CPUReservation"
namespace = "AWS/ECS"
period = "${var.low_cpu_period_seconds}"
statistic = "Maximum"
threshold = "${var.low_cpu_threshold_percent}"
dimensions = {
ClusterName = "${aws_ecs_cluster.container_instance.name}"
}
alarm_description = "Scale down if the CPUReservation is below N% for N duration"
alarm_actions = ["${aws_autoscaling_policy.container_instance_scale_down.arn}"]
depends_on = ["aws_cloudwatch_metric_alarm.container_instance_high_cpu"]
}
resource "aws_cloudwatch_metric_alarm" "container_instance_high_memory" {
alarm_name = "alarm${var.environment}${var.project}ClusterMemoryReservationHigh"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "${var.high_memory_evaluation_periods}"
metric_name = "MemoryReservation"
namespace = "AWS/ECS"
period = "${var.high_memory_period_seconds}"
statistic = "Maximum"
threshold = "${var.high_memory_threshold_percent}"
dimensions = {
ClusterName = "${aws_ecs_cluster.container_instance.name}"
}
alarm_description = "Scale up if the MemoryReservation is above N% for N duration"
alarm_actions = ["${aws_autoscaling_policy.container_instance_scale_up.arn}"]
depends_on = ["aws_cloudwatch_metric_alarm.container_instance_low_cpu"]
}
resource "aws_cloudwatch_metric_alarm" "container_instance_low_memory" {
alarm_name = "alarm${var.environment}${var.project}ClusterMemoryReservationLow"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "${var.low_memory_evaluation_periods}"
metric_name = "MemoryReservation"
namespace = "AWS/ECS"
period = "${var.low_memory_period_seconds}"
statistic = "Maximum"
threshold = "${var.low_memory_threshold_percent}"
dimensions = {
ClusterName = "${aws_ecs_cluster.container_instance.name}"
}
alarm_description = "Scale down if the MemoryReservation is below N% for N duration"
alarm_actions = ["${aws_autoscaling_policy.container_instance_scale_down.arn}"]
depends_on = ["aws_cloudwatch_metric_alarm.container_instance_high_memory"]
}