-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloudwatch.tf
271 lines (254 loc) · 10.5 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
resource "aws_cloudwatch_log_group" "backend" {
name = "${module.global_variables.env}.ridi-pay-backend"
tags = {
Environment = module.global_variables.env
}
}
data "aws_sns_topic" "cloudwatch_alarm" {
name = "cloudwatch-alarm"
}
resource "aws_cloudwatch_metric_alarm" "pay_backend_alb_5xx_error" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "pay-backend-alb-5xx-error"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = "300"
statistic = "Sum"
threshold = "10"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 ALB 5xx Error(Target 5xx 에러 제외) 10건 이상 발생"
datapoints_to_alarm = 1
dimensions = {
LoadBalancer = aws_alb.ridi_pay_backend_fargate.arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "pay_backend_cpu_utilization" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "pay-backend-cpu-utilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CpuUtilization"
namespace = "AWS/ECS"
period = "300"
statistic = "Average"
threshold = "70"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 pay-backend service 평균 CpuUtilization 70% 초과"
datapoints_to_alarm = 1
dimensions = {
ClusterName = aws_ecs_cluster.ridi_pay_backend.name
ServiceName = "ridi-pay-backend"
}
}
resource "aws_cloudwatch_metric_alarm" "pay_backend_memory_utilization" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "pay-backend-memory-utilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "MemoryUtilization"
namespace = "AWS/ECS"
period = "300"
statistic = "Average"
threshold = "85"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 pay-backend service 평균 MemoryUtilization 85% 초과"
datapoints_to_alarm = 1
dimensions = {
ClusterName = aws_ecs_cluster.ridi_pay_backend.name
ServiceName = "ridi-pay-backend"
}
}
resource "aws_cloudwatch_metric_alarm" "pay_backend_unhealthy_host_count" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "pay-backend-unhealthy-host-count"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "UnHealthyHostCount"
namespace = "AWS/ApplicationELB"
period = "300"
statistic = "Maximum"
threshold = "1"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "ECS Task 1개 이상 Unhealthy"
datapoints_to_alarm = 1
dimensions = {
LoadBalancer = aws_alb.ridi_pay_backend_fargate.arn_suffix
TargetGroup = aws_alb_target_group.ridi_pay_backend.arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "elasticache_001_cpu_utilization" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "elasticache-001-cpu-utilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/ElastiCache"
metric_name = "CPUUtilization"
period = "300"
statistic = "Average"
threshold = "45"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 ElastiCache-001 평균 CPUUtilization vCPU당 45%, 총 90% 이상 / https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/CacheMetrics.WhichShouldIMonitor.html 참고"
datapoints_to_alarm = 1
dimensions = {
CacheClusterId = aws_elasticache_replication_group.redis[0].id
CacheNodeId = "0001"
}
}
resource "aws_cloudwatch_metric_alarm" "elasticache_001_swap_usage" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "elasticache-001-swap-usage"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/ElastiCache"
metric_name = "SwapUsage"
period = "300"
statistic = "Maximum"
threshold = 50 * 1024 * 1024
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 ElastiCache-001 최대 SwapUsage 50MB 이상 / https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/CacheMetrics.WhichShouldIMonitor.html 참고"
datapoints_to_alarm = 1
dimensions = {
CacheClusterId = aws_elasticache_replication_group.redis[0].id
CacheNodeId = "0001"
}
}
resource "aws_cloudwatch_metric_alarm" "elasticache_001_freeable_memory" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "elasticache-001-freeable-memory"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/ElastiCache"
metric_name = "FreeableMemory"
period = "300"
statistic = "Minimum"
threshold = 2 * 1024 * 1024 * 1024
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 ElastiCache-001 최소 FreeableMemory 2GB(30%) 이하"
datapoints_to_alarm = 1
dimensions = {
CacheClusterId = aws_elasticache_replication_group.redis[0].id
CacheNodeId = "0001"
}
}
resource "aws_cloudwatch_metric_alarm" "elasticache_001_is_master" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "elasticache-001-is-master"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
namespace = "AWS/ElastiCache"
metric_name = "IsMaster"
period = "300"
statistic = "Minimum"
threshold = "1"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 ElastiCache-001 Node Fail 발생"
datapoints_to_alarm = 1
dimensions = {
CacheClusterId = aws_elasticache_replication_group.redis[0].id
CacheNodeId = "0001"
}
}
resource "aws_cloudwatch_metric_alarm" "rds_master_error_log" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "rds-master-error-log"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "IncomingLogEvents"
namespace = "AWS/Logs"
period = "300"
statistic = "Sum"
threshold = "1"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 RDS error log 1건 이상 발생"
datapoints_to_alarm = 1
dimensions = {
LogGroupName = "/aws/rds/instance/ridi-pay-prod-master/error"
}
}
resource "aws_cloudwatch_metric_alarm" "rds_master_cpu_utilization" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "rds-master-cpu-utilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/RDS"
period = "300"
statistic = "Average"
threshold = "70"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 RDS master 평균 CPUUtilization 70% 이상"
datapoints_to_alarm = 1
dimensions = {
DBInstanceIdentifier = "ridi-pay-prod-master"
}
}
resource "aws_cloudwatch_metric_alarm" "rds_master_freeable_memory" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "rds-master-freeable-memory"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/RDS"
metric_name = "FreeableMemory"
period = "300"
statistic = "Minimum"
threshold = 100 * 1024 * 1024
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 RDS master 최소 FreeableMemory 100MB 이하"
datapoints_to_alarm = 1
dimensions = {
DBInstanceIdentifier = "ridi-pay-prod-master"
}
}
resource "aws_cloudwatch_metric_alarm" "rds_master_free_storage_space" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "rds-master-free-storage-space"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/RDS"
metric_name = "FreeStorageSpace"
period = "300"
statistic = "Minimum"
threshold = 75 * 1024 * 1024 * 1024
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 RDS master 최소 FreeStorageSpace 75GB(30%) 이하"
datapoints_to_alarm = 1
dimensions = {
DBInstanceIdentifier = "ridi-pay-prod-master"
}
}
resource "aws_cloudwatch_metric_alarm" "rds_master_swap_usage" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "rds-master-swap-usage"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "SwapUsage"
namespace = "AWS/RDS"
period = "300"
statistic = "Maximum"
threshold = 100 * 1024 * 1024
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 최대 SwapUsage 100MB 이상"
datapoints_to_alarm = 1
dimensions = {
DBInstanceIdentifier = "ridi-pay-prod-master"
}
}
resource "aws_cloudwatch_metric_alarm" "rds_master_database_connections" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "rds-master-database-connections"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "DatabaseConnections"
namespace = "AWS/RDS"
period = "300"
statistic = "Maximum"
threshold = "440"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "최근 5분 동안 최대 DatabaseConnections 440개(70%) 이상"
datapoints_to_alarm = 1
dimensions = {
DBInstanceIdentifier = "ridi-pay-prod-master"
}
}