-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloutwatch-alarms-alb.tf
78 lines (70 loc) · 3.1 KB
/
cloutwatch-alarms-alb.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
resource "aws_cloudwatch_metric_alarm" "alb_500_errors" {
count = var.alb && length(var.alarm_sns_topics) > 0 && var.alarm_alb_500_errors_threshold != 0 ? 1 : 0
alarm_name = "${try(data.aws_iam_account_alias.current[0].account_alias, var.alarm_prefix)}-ecs-${var.name}-alb-500-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = "300"
statistic = "Maximum"
threshold = var.alarm_alb_500_errors_threshold
alarm_description = "Number of 500 errors at ALB above threshold"
alarm_actions = var.alarm_sns_topics
ok_actions = var.alarm_sns_topics
insufficient_data_actions = []
treat_missing_data = "ignore"
dimensions = {
LoadBalancer = aws_lb.ecs[0].arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "alb_400_errors" {
count = var.alb && length(var.alarm_sns_topics) > 0 && var.alarm_alb_400_errors_threshold != 0 ? 1 : 0
alarm_name = "${try(data.aws_iam_account_alias.current[0].account_alias, var.alarm_prefix)}-ecs-${var.name}-alb-400-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "HTTPCode_ELB_4XX_Count"
namespace = "AWS/ApplicationELB"
period = "300"
statistic = "Maximum"
threshold = var.alarm_alb_400_errors_threshold
alarm_description = "Number of 400 errors at ALB above threshold"
alarm_actions = var.alarm_sns_topics
ok_actions = var.alarm_sns_topics
insufficient_data_actions = []
treat_missing_data = "ignore"
dimensions = {
LoadBalancer = aws_lb.ecs[0].arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "alb_latency" {
count = var.alb && length(var.alarm_sns_topics) > 0 && var.alarm_alb_latency_anomaly_threshold > 0 ? 1 : 0
alarm_name = "${try(data.aws_iam_account_alias.current[0].account_alias, var.alarm_prefix)}-ecs-${var.name}-alb-latency"
comparison_operator = "GreaterThanUpperThreshold"
evaluation_periods = "2"
datapoints_to_alarm = "2"
threshold_metric_id = "ad1"
alarm_description = "Load balancer latency for application"
alarm_actions = var.alarm_sns_topics
ok_actions = var.alarm_sns_topics
insufficient_data_actions = []
treat_missing_data = "ignore"
metric_query {
id = "ad1"
expression = "ANOMALY_DETECTION_BAND(m1, ${var.alarm_alb_latency_anomaly_threshold})"
label = "TargetResponseTime (Expected)"
return_data = "true"
}
metric_query {
id = "m1"
return_data = "true"
metric {
metric_name = "TargetResponseTime"
namespace = "AWS/ApplicationELB"
period = "900"
stat = "p90"
dimensions = {
LoadBalancer = aws_lb.ecs[0].arn_suffix
}
}
}
}