Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Oldest Replication Slot Lag RDS alarm #49

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions alarms.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
locals {
thresholds = {
BurstBalanceThreshold = min(max(var.burst_balance_threshold, 0), 100)
CPUUtilizationThreshold = min(max(var.cpu_utilization_threshold, 0), 100)
CPUCreditBalanceThreshold = max(var.cpu_credit_balance_threshold, 0)
DiskQueueDepthThreshold = max(var.disk_queue_depth_threshold, 0)
FreeableMemoryThreshold = max(var.freeable_memory_threshold, 0)
FreeStorageSpaceThreshold = max(var.free_storage_space_threshold, 0)
SwapUsageThreshold = max(var.swap_usage_threshold, 0)
BurstBalanceThreshold = min(max(var.burst_balance_threshold, 0), 100)
CPUUtilizationThreshold = min(max(var.cpu_utilization_threshold, 0), 100)
CPUCreditBalanceThreshold = max(var.cpu_credit_balance_threshold, 0)
DiskQueueDepthThreshold = max(var.disk_queue_depth_threshold, 0)
FreeableMemoryThreshold = max(var.freeable_memory_threshold, 0)
FreeStorageSpaceThreshold = max(var.free_storage_space_threshold, 0)
OldestReplicationThreshold = max(var.oldest_replication_threshold, 0)
SwapUsageThreshold = max(var.swap_usage_threshold, 0)
}

alarm_names = toset([
Expand All @@ -16,6 +17,7 @@ locals {
"disk_queue_depth_too_high",
"freeable_memory_too_low",
"free_storage_space_threshold",
"oldest_replication_too_high",
"swap_usage_too_high"
])
}
Expand Down Expand Up @@ -139,6 +141,25 @@ resource "aws_cloudwatch_metric_alarm" "free_storage_space_too_low" {
}
}

resource "aws_cloudwatch_metric_alarm" "oldest_replication_too_high" {
alarm_name = module.label["oldest_replication_too_high"].id
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "OldestReplicationSlotLag"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["OldestReplicationThreshold"]
alarm_description = "Average database replication lag over last 10 minutes too high, disk may fill"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn

dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}


resource "aws_cloudwatch_metric_alarm" "swap_usage_too_high" {
alarm_name = module.label["swap_usage_too_high"].id
comparison_operator = "GreaterThanThreshold"
Expand Down
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ variable "free_storage_space_threshold" {
# 2 Gigabyte in Byte
}

variable "oldest_replication_threshold" {
description = "The maximum amount of replication lag space in Megabyte."
type = string
default = 1000
# 1 Gigabyte in Megabyte
}

variable "swap_usage_threshold" {
description = "The maximum amount of swap space used on the DB instance in Byte."
type = number
Expand Down