Skip to content

Commit

Permalink
Update alarms for elasticache serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
hazmei committed Dec 22, 2023
1 parent 43072ea commit bf5faf1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
41 changes: 37 additions & 4 deletions alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
}

# ElastiCache Serverless
resource "aws_cloudwatch_metric_alarm" "cache_ecpu" {
resource "aws_cloudwatch_metric_alarm" "cache_serverless_ecpu" {
count = var.enabled && var.use_serverless ? 1 : 0

alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-cpu-utilization"
alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-ecpu-utilization"
alarm_description = "Redis serverless ECPU utilization"

comparison_operator = "GreaterThanThreshold"
Expand Down Expand Up @@ -92,7 +92,38 @@ resource "aws_cloudwatch_metric_alarm" "cache_ecpu" {
]
}

resource "aws_cloudwatch_metric_alarm" "cache_throttled_commands" {
resource "aws_cloudwatch_metric_alarm" "cache_serverless_memory" {
count = var.enabled && var.use_serverless ? 1 : 0

alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-max-memory"
alarm_description = "Redis serverless max memory"

comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1

metric_name = "BytesUsedForCache"
namespace = "AWS/ElastiCache"

period = 60
statistic = "Average"

threshold = (var.max_data_storage * 1024 * 1024 * 1024) - var.alarm_memory_threshold_bytes

tags = var.tags

dimensions = {
CacheClusterId = awscc_elasticache_serverless_cache.this[0].serverless_cache_name
}

alarm_actions = var.alarm_actions
ok_actions = var.ok_actions

depends_on = [
aws_elasticache_replication_group.this
]
}

resource "aws_cloudwatch_metric_alarm" "cache_serverless_throttled_commands" {
count = var.enabled && var.use_serverless ? 1 : 0

alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-throttled-commands"
Expand All @@ -110,7 +141,9 @@ resource "aws_cloudwatch_metric_alarm" "cache_throttled_commands" {
threshold = 0

tags = var.tags
dimensions = {}
dimensions = {
CacheClusterId = awscc_elasticache_serverless_cache.this[0].serverless_cache_name
}

alarm_actions = var.alarm_actions
ok_actions = var.ok_actions
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ resource "awscc_elasticache_serverless_cache" "this" {
}
}

user_group_id = var.user_group_id
user_group_id = var.serverless_user_group_id

final_snapshot_name = "${var.name}-elasticache-serverless-final-snapshot"
kms_key_id = var.kms_key_id
Expand Down
8 changes: 4 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ variable "use_serverless" {

variable "max_data_storage" {
type = number
description = "The maximun cached data capacity of the Serverless Cache"
description = "The maximun cached data capacity of the Serverless Cache in GB"
default = 10

validation {
Expand All @@ -222,7 +222,7 @@ variable "max_ecpu_per_second" {
variable "daily_snapshot_time" {
type = string
description = "The daily time range (in UTC) during which the service takes automatic snapshot of the Serverless Cache"
default = "09:00"
default = "18:00"
}

variable "snapshot_arns_to_restore" {
Expand All @@ -231,8 +231,8 @@ variable "snapshot_arns_to_restore" {
default = []
}

variable "user_group_id" {
variable "serverless_user_group_id" {
type = string
description = "The ID of the user group"
description = "The ID of the user group for Serverless Cache"
default = ""
}

0 comments on commit bf5faf1

Please sign in to comment.