-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcloudwatch_alerts.tf
75 lines (66 loc) · 2.24 KB
/
cloudwatch_alerts.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
/*
Module: ECS-Fargate-Appmesh
Version: 1.0.0
This file will create following cloudwatch alerts:
- when fargate container reach 80% or above cpu usage
- when fargate container has 60% or below cpu usage
Actions:
- add new container on high cpu usage alert
- remove container on low cpu usage alert
*/
// cloudWatch alarm that triggers the autoscaling up policy
resource "aws_cloudwatch_metric_alarm" "service_cpu_high" {
// set alarm name
alarm_name = "${var.prefix}-${var.env}-${var.app_name}-cpu-utilization-high"
// when cpu usage is greater or equal to threshold
comparison_operator = "GreaterThanOrEqualToThreshold"
// evaluate this alert every 2 seconds
evaluation_periods = "2"
// alert set for CPU utilization
metric_name = "CPUUtilization"
// name space for aws/ecs
namespace = "AWS/ECS"
// trigger alert when usage is equal or above 80% for 1 min.
period = "60"
// statistic type
statistic = "Average"
// trigger when cpu at 80% or above for 1 min.
threshold = "80"
// dimensions for alert
dimensions = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.main.name
}
// run scaling up policy when this alert gets triggered
alarm_actions = [aws_appautoscaling_policy.up.arn]
// add tags
tags = var.tags
}
// cloudWatch alarm that triggers the auto scaling down policy
resource "aws_cloudwatch_metric_alarm" "service_cpu_low" {
// set alert name
alarm_name = "${var.prefix}-${var.env}-${var.app_name}-cpu-utilization-low"
// when cpu usage is below or equal to threshold
comparison_operator = "LessThanOrEqualToThreshold"
// evaluate this alert every 2 seconds
evaluation_periods = "2"
// alert set for CPU utilization
metric_name = "CPUUtilization"
// name space for aws/ecs
namespace = "AWS/ECS"
// trigger alert when usage is equal or below 60% for 1 min.
period = "60"
// statistic type
statistic = "Average"
// trigger when cpu at 60% or below for 1 min.
threshold = "60"
// dimensions for alert
dimensions = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.main.name
}
// run scaling up policy when this alert gets triggered
alarm_actions = [aws_appautoscaling_policy.down.arn]
// add tags
tags = var.tags
}