diff --git a/addons/monitoring/.header.md b/addons/monitoring/.header.md index ca316bf..a073f13 100644 --- a/addons/monitoring/.header.md +++ b/addons/monitoring/.header.md @@ -146,6 +146,36 @@ module "monitoring" { } ``` +# Configurable Alert Thresholds + +All CloudWatch alarm thresholds, periods, and evaluation periods can be overridden via the `alert_thresholds` object. Each alarm type is optional — omit any field to use the module default. + +| Field | Alarm | Default threshold | Default period | Default evaluation periods | +|---|---|---|---|---| +| `rds_cpu` | RDS CPU Utilization | 80 | 300s | 1 | +| `redis_cpu` | Redis CPU Utilization | 70 | 300s | 1 | +| `redis_cpu_engine` | Redis Engine CPU Utilization | 25 | 300s | 1 | +| `redis_memory` | Redis Database Memory % | 80 | 300s | 1 | +| `acm_cert_expiry` | ACM Certificate Expiry | 30 days | 86400s | 1 | +| `alb_healthyhosts` | ALB Healthy Host Count | 1 | 60s | 1 | + +Example — raise the RDS CPU threshold and require 3 consecutive 5-minute periods before firing (15 minutes total): + +```hcl +module "monitoring" { + # ... + alert_thresholds = { + rds_cpu = { + threshold = 90 + period = 300 + evaluation_periods = 3 + } + } +} +``` + +Anomaly detection alarms (`redis_current_connections`, `redis_replication_lag`, `target_response_time`) are not included — they use CloudWatch anomaly detection bands and do not have a simple threshold/period/evaluation_periods structure. + # SNS topic ARNs map Valid targets for `sns_topic_arns_map`: diff --git a/addons/monitoring/README.md b/addons/monitoring/README.md index 932c4b0..e7dcd19 100644 --- a/addons/monitoring/README.md +++ b/addons/monitoring/README.md @@ -146,6 +146,36 @@ module "monitoring" { } ``` +# Configurable Alert Thresholds + +All CloudWatch alarm thresholds, periods, and evaluation periods can be overridden via the `alert_thresholds` object. Each alarm type is optional — omit any field to use the module default. + +| Field | Alarm | Default threshold | Default period | Default evaluation periods | +|---|---|---|---|---| +| `rds_cpu` | RDS CPU Utilization | 80 | 300s | 1 | +| `redis_cpu` | Redis CPU Utilization | 70 | 300s | 1 | +| `redis_cpu_engine` | Redis Engine CPU Utilization | 25 | 300s | 1 | +| `redis_memory` | Redis Database Memory % | 80 | 300s | 1 | +| `acm_cert_expiry` | ACM Certificate Expiry | 30 days | 86400s | 1 | +| `alb_healthyhosts` | ALB Healthy Host Count | 1 | 60s | 1 | + +Example — raise the RDS CPU threshold and require 3 consecutive 5-minute periods before firing (15 minutes total): + +```hcl +module "monitoring" { + # ... + alert_thresholds = { + rds_cpu = { + threshold = 90 + period = 300 + evaluation_periods = 3 + } + } +} +``` + +Anomaly detection alarms (`redis_current_connections`, `redis_replication_lag`, `target_response_time`) are not included — they use CloudWatch anomaly detection bands and do not have a simple threshold/period/evaluation\_periods structure. + # SNS topic ARNs map Valid targets for `sns_topic_arns_map`: @@ -196,14 +226,14 @@ Deprecated (typo) aliases are still accepted for backwards compatibility: ## Requirements | Name | Version | -|------|---------| +| ---- | ------- | | [terraform](#requirement\_terraform) | >= 1.12.0 | | [aws](#requirement\_aws) | >= 6.37.0 | ## Providers | Name | Version | -|------|---------| +| ---- | ------- | | [archive](#provider\_archive) | 2.7.1 | | [aws](#provider\_aws) | 6.39.0 | | [null](#provider\_null) | 3.2.4 | @@ -215,7 +245,7 @@ No modules. ## Resources | Name | Type | -|------|------| +| ---- | ---- | | [aws_cloudwatch_event_rule.cron_monitoring_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource | | [aws_cloudwatch_event_target.cron_monitoring_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource | | [aws_cloudwatch_log_group.cron_monitoring_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource | @@ -255,9 +285,10 @@ No modules. ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +| ---- | ----------- | ---- | ------- | :------: | | [acm\_certificate\_arn](#input\_acm\_certificate\_arn) | n/a | `string` | `null` | no | | [albs](#input\_albs) | n/a |
list(object({
name = string
arn_suffix = string
target_group_name = string
target_group_arn_suffix = string
min_containers = optional(string, 1)
ecs_service_name = string
alert_thresholds = optional(
object({
HTTPCode_ELB_5XX_Count = object({
period = number
threshold = number
})
HTTPCode_Target_5XX_Count = object({
period = number
threshold = number
})
}),
{
HTTPCode_ELB_5XX_Count = {
period = 120
threshold = 0
},
HTTPCode_Target_5XX_Count = {
period = 120
threshold = 0
}
}
)
}))
| `[]` | no | +| [alert\_thresholds](#input\_alert\_thresholds) | CloudWatch alarm threshold overrides. Each alarm type is optional; omitted fields use the defaults below. |
object({
rds_cpu = optional(object({
threshold = number
period = number
evaluation_periods = number
}), {
threshold = 80
period = 300
evaluation_periods = 1
})
redis_cpu = optional(object({
threshold = number
period = number
evaluation_periods = number
}), {
threshold = 70
period = 300
evaluation_periods = 1
})
redis_cpu_engine = optional(object({
threshold = number
period = number
evaluation_periods = number
}), {
threshold = 25
period = 300
evaluation_periods = 1
})
redis_memory = optional(object({
threshold = number
period = number
evaluation_periods = number
}), {
threshold = 80
period = 300
evaluation_periods = 1
})
acm_cert_expiry = optional(object({
threshold = number
period = number
evaluation_periods = number
}), {
threshold = 30
period = 86400
evaluation_periods = 1
})
alb_healthyhosts = optional(object({
threshold = number
period = number
evaluation_periods = number
}), {
threshold = 1
period = 60
evaluation_periods = 1
})
})
|
{
"acm_cert_expiry": {
"evaluation_periods": 1,
"period": 86400,
"threshold": 30
},
"alb_healthyhosts": {
"evaluation_periods": 1,
"period": 60,
"threshold": 1
},
"rds_cpu": {
"evaluation_periods": 1,
"period": 300,
"threshold": 80
},
"redis_cpu": {
"evaluation_periods": 1,
"period": 300,
"threshold": 70
},
"redis_cpu_engine": {
"evaluation_periods": 1,
"period": 300,
"threshold": 25
},
"redis_memory": {
"evaluation_periods": 1,
"period": 300,
"threshold": 80
}
}
| no | | [cron\_monitoring](#input\_cron\_monitoring) | n/a |
object({
mysql_host = string
mysql_database = string
mysql_user = string
mysql_password_secret_name = string
mysql_password_secret_kms_key_arn = optional(string, null)
mysql_tls_config = optional(string, "true")
vpc_id = string
subnet_ids = list(string)
rds_security_group_id = string
delay_tolerance = string
run_interval = string
log_retention_in_days = optional(number, 7)
ignore_list = optional(list(string), [])
lambda_kms = optional(object({
cmk_enabled = optional(bool, false)
kms_key_arn = optional(string, null)
kms_alias = optional(string, "fleet-cron-monitoring")
kms_base_policy = optional(list(object({
sid = string
effect = string
principals = object({
type = string
identifiers = list(string)
})
actions = list(string)
resources = list(string)
conditions = optional(list(object({
test = string
variable = string
values = list(string)
})), [])
})), null)
extra_kms_policies = optional(list(any), [])
}), {
cmk_enabled = false
kms_key_arn = null
kms_alias = "fleet-cron-monitoring"
kms_base_policy = null
extra_kms_policies = []
})
})
| `null` | no | | [customer\_prefix](#input\_customer\_prefix) | n/a | `string` | `"fleet"` | no | | [default\_sns\_topic\_arns](#input\_default\_sns\_topic\_arns) | n/a | `list(string)` | `[]` | no | @@ -270,6 +301,6 @@ No modules. ## Outputs | Name | Description | -|------|-------------| +| ---- | ----------- | | [cron\_monitoring\_lambda\_arn](#output\_cron\_monitoring\_lambda\_arn) | n/a | | [cron\_monitoring\_lambda\_role\_arn](#output\_cron\_monitoring\_lambda\_role\_arn) | n/a | diff --git a/addons/monitoring/main.tf b/addons/monitoring/main.tf index f03bfb9..dbf1666 100644 --- a/addons/monitoring/main.tf +++ b/addons/monitoring/main.tf @@ -3,12 +3,12 @@ resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high" { for_each = toset(var.mysql_cluster_members) alarm_name = "rds_cpu_utilization_too_high-${var.customer_prefix}-${each.key}" comparison_operator = "GreaterThanThreshold" - evaluation_periods = "1" + evaluation_periods = tostring(var.alert_thresholds.rds_cpu.evaluation_periods) metric_name = "CPUUtilization" namespace = "AWS/RDS" - period = "300" + period = tostring(var.alert_thresholds.rds_cpu.period) statistic = "Average" - threshold = 80 + threshold = var.alert_thresholds.rds_cpu.threshold alarm_description = "Average database CPU utilization over last 5 minutes too high" alarm_actions = lookup(var.sns_topic_arns_map, "rds_cpu_utilization_too_high", lookup(var.sns_topic_arns_map, "rds_cpu_untilizaton_too_high", var.default_sns_topic_arns)) ok_actions = lookup(var.sns_topic_arns_map, "rds_cpu_utilization_too_high", lookup(var.sns_topic_arns_map, "rds_cpu_untilizaton_too_high", var.default_sns_topic_arns)) @@ -154,12 +154,12 @@ resource "aws_cloudwatch_metric_alarm" "alb_healthyhosts" { for_each = local.alb_map alarm_name = "backend-healthyhosts-${var.customer_prefix}-${each.value.name}" comparison_operator = "LessThanThreshold" - evaluation_periods = "1" + evaluation_periods = tostring(var.alert_thresholds.alb_healthyhosts.evaluation_periods) metric_name = "HealthyHostCount" namespace = "AWS/ApplicationELB" - period = "60" + period = tostring(var.alert_thresholds.alb_healthyhosts.period) statistic = "Minimum" - threshold = each.value.min_containers + threshold = max(each.value.min_containers, var.alert_thresholds.alb_healthyhosts.threshold) alarm_description = "This alarm indicates the number of Healthy Fleet hosts is lower than expected. Please investigate the load balancer \"${each.value.name}\" or the target group \"${each.value.target_group_name}\" and the fleet backend service \"${each.value.ecs_service_name}\"" actions_enabled = "true" alarm_actions = lookup(var.sns_topic_arns_map, "alb_healthyhosts", lookup(var.sns_topic_arns_map, "alb_helthyhosts", var.default_sns_topic_arns)) @@ -240,15 +240,15 @@ resource "aws_cloudwatch_metric_alarm" "redis_cpu" { alarm_name = "redis-cpu-utilization-${each.key}-${var.customer_prefix}" alarm_description = "Redis cluster CPU utilization node ${each.key}" comparison_operator = "GreaterThanThreshold" - evaluation_periods = "1" + evaluation_periods = tostring(var.alert_thresholds.redis_cpu.evaluation_periods) metric_name = "CPUUtilization" namespace = "AWS/ElastiCache" - period = "300" + period = tostring(var.alert_thresholds.redis_cpu.period) statistic = "Average" alarm_actions = lookup(var.sns_topic_arns_map, "redis_cpu_utilization", var.default_sns_topic_arns) ok_actions = lookup(var.sns_topic_arns_map, "redis_cpu_utilization", var.default_sns_topic_arns) - threshold = "70" + threshold = tostring(var.alert_thresholds.redis_cpu.threshold) dimensions = { CacheClusterId = each.key @@ -261,15 +261,15 @@ resource "aws_cloudwatch_metric_alarm" "redis_cpu_engine_utilization" { alarm_name = "redis-cpu-engine-utilization-${each.key}-${var.customer_prefix}" alarm_description = "Redis cluster CPU Engine utilization node ${each.key}" comparison_operator = "GreaterThanThreshold" - evaluation_periods = "1" + evaluation_periods = tostring(var.alert_thresholds.redis_cpu_engine.evaluation_periods) metric_name = "EngineCPUUtilization" namespace = "AWS/ElastiCache" - period = "300" + period = tostring(var.alert_thresholds.redis_cpu_engine.period) statistic = "Average" alarm_actions = lookup(var.sns_topic_arns_map, "redis_cpu_engine_utilization", var.default_sns_topic_arns) ok_actions = lookup(var.sns_topic_arns_map, "redis_cpu_engine_utilization", var.default_sns_topic_arns) - threshold = "25" + threshold = tostring(var.alert_thresholds.redis_cpu_engine.threshold) dimensions = { CacheClusterId = each.key @@ -282,15 +282,15 @@ resource "aws_cloudwatch_metric_alarm" "redis-database-memory-percentage" { alarm_name = "redis-database-memory-percentage-${each.key}-${var.customer_prefix}" alarm_description = "Percentage of the memory available for the cluster that is in use. This is calculated using used_memory/maxmemory." comparison_operator = "GreaterThanThreshold" - evaluation_periods = "1" + evaluation_periods = tostring(var.alert_thresholds.redis_memory.evaluation_periods) metric_name = "DatabaseMemoryUsagePercentage" namespace = "AWS/ElastiCache" - period = "300" + period = tostring(var.alert_thresholds.redis_memory.period) statistic = "Average" alarm_actions = lookup(var.sns_topic_arns_map, "redis_database_memory_percentage", var.default_sns_topic_arns) ok_actions = lookup(var.sns_topic_arns_map, "redis_database_memory_percentage", var.default_sns_topic_arns) - threshold = "80" + threshold = tostring(var.alert_thresholds.redis_memory.threshold) dimensions = { CacheClusterId = each.key @@ -372,9 +372,9 @@ resource "aws_cloudwatch_metric_alarm" "acm_certificate_expired" { count = var.acm_certificate_arn == null ? 0 : 1 alarm_name = "acm-cert-expiry-${var.customer_prefix}" comparison_operator = "LessThanThreshold" - evaluation_periods = "1" - period = "86400" // 1 day in seconds - threshold = 30 // days + evaluation_periods = tostring(var.alert_thresholds.acm_cert_expiry.evaluation_periods) + period = tostring(var.alert_thresholds.acm_cert_expiry.period) + threshold = var.alert_thresholds.acm_cert_expiry.threshold statistic = "Average" namespace = "AWS/CertificateManager" metric_name = "DaysToExpiry" diff --git a/addons/monitoring/variables.tf b/addons/monitoring/variables.tf index 26accde..f458418 100644 --- a/addons/monitoring/variables.tf +++ b/addons/monitoring/variables.tf @@ -80,6 +80,98 @@ variable "log_monitoring" { default = {} } +variable "alert_thresholds" { + description = "CloudWatch alarm threshold overrides. Each alarm type is optional; omitted fields use the defaults below." + type = object({ + rds_cpu = optional(object({ + threshold = number + period = number + evaluation_periods = number + }), { + threshold = 80 + period = 300 + evaluation_periods = 1 + }) + redis_cpu = optional(object({ + threshold = number + period = number + evaluation_periods = number + }), { + threshold = 70 + period = 300 + evaluation_periods = 1 + }) + redis_cpu_engine = optional(object({ + threshold = number + period = number + evaluation_periods = number + }), { + threshold = 25 + period = 300 + evaluation_periods = 1 + }) + redis_memory = optional(object({ + threshold = number + period = number + evaluation_periods = number + }), { + threshold = 80 + period = 300 + evaluation_periods = 1 + }) + acm_cert_expiry = optional(object({ + threshold = number + period = number + evaluation_periods = number + }), { + threshold = 30 + period = 86400 + evaluation_periods = 1 + }) + alb_healthyhosts = optional(object({ + threshold = number + period = number + evaluation_periods = number + }), { + threshold = 1 + period = 60 + evaluation_periods = 1 + }) + }) + default = { + rds_cpu = { + threshold = 80 + period = 300 + evaluation_periods = 1 + } + redis_cpu = { + threshold = 70 + period = 300 + evaluation_periods = 1 + } + redis_cpu_engine = { + threshold = 25 + period = 300 + evaluation_periods = 1 + } + redis_memory = { + threshold = 80 + period = 300 + evaluation_periods = 1 + } + acm_cert_expiry = { + threshold = 30 + period = 86400 + evaluation_periods = 1 + } + alb_healthyhosts = { + threshold = 1 + period = 60 + evaluation_periods = 1 + } + } +} + variable "cron_monitoring" { type = object({ mysql_host = string