|
| 1 | +module "custom_elasticache_alarms" { |
| 2 | + source = "oozou/cloudwatch-alarm/aws" |
| 3 | + version = "1.0.0" |
| 4 | + |
| 5 | + for_each = var.custom_elasticache_alarms_configure |
| 6 | + depends_on = [aws_elasticache_replication_group.elasticache] |
| 7 | + |
| 8 | + prefix = var.prefix |
| 9 | + environment = var.environment |
| 10 | + name = format("%s-%s-alarm", local.service_name, each.key) |
| 11 | + |
| 12 | + alarm_description = format( |
| 13 | + "%s's %s %s %s in period %ss with %s datapoint", |
| 14 | + lookup(each.value, "metric_name", null), |
| 15 | + lookup(each.value, "statistic", "Average"), |
| 16 | + lookup(each.value, "comparison_operator", null), |
| 17 | + lookup(each.value, "threshold", null), |
| 18 | + lookup(each.value, "period", 600), |
| 19 | + lookup(each.value, "evaluation_periods", 1) |
| 20 | + ) |
| 21 | + |
| 22 | + comparison_operator = local.comparison_operators[lookup(each.value, "comparison_operator", null)] |
| 23 | + evaluation_periods = lookup(each.value, "evaluation_periods", 1) |
| 24 | + metric_name = lookup(each.value, "metric_name", null) |
| 25 | + namespace = "AWS/ElastiCache" |
| 26 | + period = lookup(each.value, "period", 600) |
| 27 | + statistic = lookup(each.value, "statistic", "Average") |
| 28 | + threshold = lookup(each.value, "threshold", null) |
| 29 | + |
| 30 | + dimensions = { |
| 31 | + CacheClusterId = aws_elasticache_replication_group.elasticache.global_replication_group_id |
| 32 | + } |
| 33 | + |
| 34 | + alarm_actions = lookup(each.value, "alarm_actions", null) |
| 35 | + ok_actions = lookup(each.value, "ok_actions", null) |
| 36 | + |
| 37 | + tags = local.tags |
| 38 | +} |
| 39 | + |
| 40 | +resource "aws_cloudwatch_metric_alarm" "redis_cpu_alarm" { |
| 41 | + count = var.is_enable_default_alarms ? 1 : 0 |
| 42 | + alarm_name = format("%s-%s-alarm", local.service_name, "redis_high_CPU") |
| 43 | + comparison_operator = "GreaterThanThreshold" |
| 44 | + evaluation_periods = "1" |
| 45 | + metric_name = "CPUUtilization" |
| 46 | + namespace = "AWS/ElastiCache" |
| 47 | + period = "600" |
| 48 | + statistic = "Average" |
| 49 | + threshold = "80" |
| 50 | + alarm_description = "This alarm will trigger if the Redis cluster's cpu usage is too high" |
| 51 | + alarm_actions = var.default_alarm_actions |
| 52 | + ok_actions = var.default_ok_actions |
| 53 | + |
| 54 | + dimensions = { |
| 55 | + CacheClusterId = aws_elasticache_replication_group.elasticache.global_replication_group_id |
| 56 | + } |
| 57 | + depends_on = [aws_elasticache_replication_group.elasticache] |
| 58 | +} |
| 59 | + |
| 60 | +resource "aws_cloudwatch_metric_alarm" "redis_memory_alarm" { |
| 61 | + count = var.is_enable_default_alarms ? 1 : 0 |
| 62 | + alarm_name = format("%s-%s-alarm", local.service_name, "redis_high_memory") |
| 63 | + comparison_operator = "GreaterThanThreshold" |
| 64 | + evaluation_periods = "1" |
| 65 | + metric_name = "DatabaseMemoryUsagePercentage" |
| 66 | + namespace = "AWS/ElastiCache" |
| 67 | + period = "600" |
| 68 | + statistic = "Average" |
| 69 | + threshold = "80" |
| 70 | + alarm_description = "This alarm will trigger if the Redis cluster's memory usage is too high" |
| 71 | + alarm_actions = var.default_alarm_actions |
| 72 | + ok_actions = var.default_ok_actions |
| 73 | + |
| 74 | + dimensions = { |
| 75 | + CacheClusterId = aws_elasticache_replication_group.elasticache.global_replication_group_id |
| 76 | + } |
| 77 | + depends_on = [aws_elasticache_replication_group.elasticache] |
| 78 | +} |
| 79 | + |
0 commit comments