Skip to content

Commit 224a3a4

Browse files
Split alarm modules into files
1 parent efa830e commit 224a3a4

15 files changed

Lines changed: 209 additions & 218 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_cloudwatch_metric_alarm" "five_xx" {
2+
alarm_name = "${var.alarm_prefix}-apigw-5xx"
3+
alarm_description = "RELIABILITY: API Gateway 5xx responses"
4+
5+
namespace = "AWS/ApiGateway"
6+
metric_name = "5XXError"
7+
statistic = "Sum"
8+
period = var.error_5xx_period_seconds
9+
10+
evaluation_periods = var.error_5xx_evaluation_periods
11+
threshold = var.error_5xx_threshold
12+
comparison_operator = "GreaterThanThreshold"
13+
treat_missing_data = "notBreaching"
14+
15+
dimensions = local.api_dimensions
16+
17+
actions_enabled = false
18+
alarm_actions = []
19+
ok_actions = []
20+
insufficient_data_actions = []
21+
tags = var.tags
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "aws_cloudwatch_metric_alarm" "latency_anomaly" {
2+
alarm_name = "${var.alarm_prefix}-apigw-latency-anomaly"
3+
alarm_description = "RELIABILITY: API Gateway latency anomaly"
4+
comparison_operator = "GreaterThanUpperThreshold"
5+
evaluation_periods = var.latency_evaluation_periods
6+
datapoints_to_alarm = var.latency_datapoints_to_alarm
7+
threshold_metric_id = "ad1"
8+
treat_missing_data = "notBreaching"
9+
10+
actions_enabled = false
11+
alarm_actions = []
12+
ok_actions = []
13+
insufficient_data_actions = []
14+
tags = var.tags
15+
16+
metric_query {
17+
id = "m1"
18+
metric {
19+
metric_name = "Latency"
20+
namespace = "AWS/ApiGateway"
21+
stat = "Average"
22+
period = var.latency_period_seconds
23+
dimensions = local.api_dimensions
24+
}
25+
return_data = true
26+
}
27+
28+
metric_query {
29+
id = "ad1"
30+
expression = "ANOMALY_DETECTION_BAND(m1, ${var.latency_anomaly_sensitivity})"
31+
label = "Latency (expected)"
32+
return_data = true
33+
}
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_cloudwatch_metric_alarm" "latency_threshold" {
2+
alarm_name = "${var.alarm_prefix}-apigw-latency-threshold"
3+
alarm_description = "RELIABILITY: API Gateway latency above threshold"
4+
5+
namespace = "AWS/ApiGateway"
6+
metric_name = "Latency"
7+
statistic = "Average"
8+
period = var.latency_period_seconds
9+
10+
evaluation_periods = var.latency_evaluation_periods
11+
threshold = var.latency_threshold_ms
12+
comparison_operator = "GreaterThanThreshold"
13+
treat_missing_data = "notBreaching"
14+
15+
dimensions = local.api_dimensions
16+
17+
actions_enabled = false
18+
alarm_actions = []
19+
ok_actions = []
20+
insufficient_data_actions = []
21+
tags = var.tags
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
locals {
2+
api_dimensions = {
3+
ApiName = var.api_name
4+
Stage = var.stage_name
5+
}
6+
}

infrastructure/terraform/modules/alarms/alarms-apigw/main.tf

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_cloudwatch_metric_alarm" "read_throttle" {
2+
alarm_name = "${var.alarm_prefix}-ddb-${var.table_name}-read-throttle"
3+
alarm_description = "RELIABILITY: DynamoDB read throttling"
4+
5+
namespace = "AWS/DynamoDB"
6+
metric_name = "ReadThrottleEvents"
7+
statistic = "Sum"
8+
period = var.period_seconds
9+
10+
evaluation_periods = var.evaluation_periods
11+
threshold = var.read_throttle_threshold
12+
comparison_operator = "GreaterThanThreshold"
13+
treat_missing_data = "notBreaching"
14+
15+
dimensions = { TableName = var.table_name }
16+
17+
actions_enabled = false
18+
alarm_actions = []
19+
ok_actions = []
20+
insufficient_data_actions = []
21+
tags = var.tags
22+
}

infrastructure/terraform/modules/alarms/alarms-ddb/main.tf renamed to infrastructure/terraform/modules/alarms/alarms-ddb/alarm-write-throttle.tf

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
resource "aws_cloudwatch_metric_alarm" "read_throttle" {
2-
alarm_name = "${var.alarm_prefix}-ddb-${var.table_name}-read-throttle"
3-
alarm_description = "RELIABILITY: DynamoDB read throttling"
4-
5-
namespace = "AWS/DynamoDB"
6-
metric_name = "ReadThrottleEvents"
7-
statistic = "Sum"
8-
period = var.period_seconds
9-
10-
evaluation_periods = var.evaluation_periods
11-
threshold = var.read_throttle_threshold
12-
comparison_operator = "GreaterThanThreshold"
13-
treat_missing_data = "notBreaching"
14-
15-
dimensions = { TableName = var.table_name }
16-
17-
actions_enabled = false
18-
alarm_actions = []
19-
ok_actions = []
20-
insufficient_data_actions = []
21-
tags = var.tags
22-
}
23-
241
resource "aws_cloudwatch_metric_alarm" "write_throttle" {
252
alarm_name = "${var.alarm_prefix}-ddb-${var.table_name}-write-throttle"
263
alarm_description = "RELIABILITY: DynamoDB write throttling"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "aws_cloudwatch_metric_alarm" "error_logs" {
2+
count = var.enable_error_log_metric ? 1 : 0
3+
alarm_name = "${var.alarm_prefix}-lambda-${var.function_name}-error-logs"
4+
alarm_description = "ERROR: Lambda error logs detected"
5+
6+
namespace = var.error_log_metric_namespace
7+
metric_name = "${var.error_log_metric_name_prefix}${var.function_name}"
8+
statistic = "Sum"
9+
period = var.period_seconds
10+
11+
evaluation_periods = var.error_log_evaluation_periods
12+
threshold = var.error_log_threshold
13+
comparison_operator = "GreaterThanThreshold"
14+
treat_missing_data = "notBreaching"
15+
16+
actions_enabled = false
17+
alarm_actions = []
18+
ok_actions = []
19+
insufficient_data_actions = []
20+
tags = var.tags
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_cloudwatch_metric_alarm" "errors" {
2+
alarm_name = "${var.alarm_prefix}-lambda-${var.function_name}-errors"
3+
alarm_description = "ERROR: Lambda errors"
4+
5+
namespace = "AWS/Lambda"
6+
metric_name = "Errors"
7+
statistic = "Sum"
8+
period = var.period_seconds
9+
10+
evaluation_periods = var.evaluation_periods
11+
threshold = var.errors_threshold
12+
comparison_operator = "GreaterThanThreshold"
13+
treat_missing_data = "notBreaching"
14+
15+
dimensions = { FunctionName = var.function_name }
16+
17+
actions_enabled = false
18+
alarm_actions = []
19+
ok_actions = []
20+
insufficient_data_actions = []
21+
tags = var.tags
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_cloudwatch_metric_alarm" "throttles" {
2+
alarm_name = "${var.alarm_prefix}-lambda-${var.function_name}-throttles"
3+
alarm_description = "RELIABILITY: Lambda throttles"
4+
5+
namespace = "AWS/Lambda"
6+
metric_name = "Throttles"
7+
statistic = "Sum"
8+
period = var.period_seconds
9+
10+
evaluation_periods = var.evaluation_periods
11+
threshold = var.throttles_threshold
12+
comparison_operator = "GreaterThanThreshold"
13+
treat_missing_data = "notBreaching"
14+
15+
dimensions = { FunctionName = var.function_name }
16+
17+
actions_enabled = false
18+
alarm_actions = []
19+
ok_actions = []
20+
insufficient_data_actions = []
21+
tags = var.tags
22+
}

0 commit comments

Comments
 (0)