Difference between revisions of "Terraform resource: aws cloudwatch metric alarm"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
* https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm | * https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm | ||
+ | |||
+ | <pre> | ||
+ | resource "aws_cloudwatch_metric_alarm" "db_cpu_utilization_too_high" { | ||
+ | alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-highCPUUtilization") | ||
+ | comparison_operator = "GreaterThanThreshold" | ||
+ | evaluation_periods = "5" | ||
+ | metric_name = "CPUUtilization" | ||
+ | namespace = "AWS/RDS" | ||
+ | period = "120" | ||
+ | statistic = "Average" | ||
+ | threshold = "80" | ||
+ | alarm_description = "Average database CPU utilization is too high." | ||
+ | |||
+ | dimensions = { | ||
+ | DBInstanceIdentifier = aws_db_instance.rds_instance.id | ||
+ | } | ||
+ | } | ||
+ | |||
+ | resource "aws_cloudwatch_metric_alarm" "db_disk_queue_depth_too_high" { | ||
+ | alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-highDiskQueueDepth") | ||
+ | comparison_operator = "GreaterThanThreshold" | ||
+ | evaluation_periods = "2" | ||
+ | metric_name = "DiskQueueDepth" | ||
+ | namespace = "AWS/RDS" | ||
+ | period = "120" | ||
+ | statistic = "Average" | ||
+ | threshold = "10" | ||
+ | alarm_description = "Average database disk queue depth is too high, performance may be negatively impacted." | ||
+ | |||
+ | dimensions = { | ||
+ | DBInstanceIdentifier = aws_db_instance.rds_instance.id | ||
+ | } | ||
+ | } | ||
+ | |||
+ | resource "aws_cloudwatch_metric_alarm" "db_disk_free_storage_space_too_low" { | ||
+ | alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-lowFreeStorageSpace") | ||
+ | comparison_operator = "LessThanThreshold" | ||
+ | evaluation_periods = "2" | ||
+ | metric_name = "FreeStorageSpace" | ||
+ | namespace = "AWS/RDS" | ||
+ | period = "120" | ||
+ | statistic = "Average" | ||
+ | threshold = "10" | ||
+ | alarm_description = "Average database free storage space is too low and may fill up soon." | ||
+ | |||
+ | dimensions = { | ||
+ | DBInstanceIdentifier = aws_db_instance.rds_instance.id | ||
+ | } | ||
+ | } | ||
+ | |||
+ | resource "aws_cloudwatch_metric_alarm" "db_memory_freeable_too_low" { | ||
+ | alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-lowFreeableMemory") | ||
+ | comparison_operator = "LessThanThreshold" | ||
+ | evaluation_periods = "2" | ||
+ | metric_name = "FreeableMemory" | ||
+ | namespace = "AWS/RDS" | ||
+ | period = "120" | ||
+ | statistic = "Average" | ||
+ | threshold = "10" | ||
+ | alarm_description = "Average database freeable memory is too low, performance may be negatively impacted." | ||
+ | |||
+ | dimensions = { | ||
+ | DBInstanceIdentifier = aws_db_instance.rds_instance.id | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | |||
Revision as of 07:09, 16 January 2023
resource "aws_cloudwatch_metric_alarm" "db_cpu_utilization_too_high" { alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-highCPUUtilization") comparison_operator = "GreaterThanThreshold" evaluation_periods = "5" metric_name = "CPUUtilization" namespace = "AWS/RDS" period = "120" statistic = "Average" threshold = "80" alarm_description = "Average database CPU utilization is too high." dimensions = { DBInstanceIdentifier = aws_db_instance.rds_instance.id } } resource "aws_cloudwatch_metric_alarm" "db_disk_queue_depth_too_high" { alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-highDiskQueueDepth") comparison_operator = "GreaterThanThreshold" evaluation_periods = "2" metric_name = "DiskQueueDepth" namespace = "AWS/RDS" period = "120" statistic = "Average" threshold = "10" alarm_description = "Average database disk queue depth is too high, performance may be negatively impacted." dimensions = { DBInstanceIdentifier = aws_db_instance.rds_instance.id } } resource "aws_cloudwatch_metric_alarm" "db_disk_free_storage_space_too_low" { alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-lowFreeStorageSpace") comparison_operator = "LessThanThreshold" evaluation_periods = "2" metric_name = "FreeStorageSpace" namespace = "AWS/RDS" period = "120" statistic = "Average" threshold = "10" alarm_description = "Average database free storage space is too low and may fill up soon." dimensions = { DBInstanceIdentifier = aws_db_instance.rds_instance.id } } resource "aws_cloudwatch_metric_alarm" "db_memory_freeable_too_low" { alarm_name = format("%s-%s", lower("${var.rds_name}"), "db-lowFreeableMemory") comparison_operator = "LessThanThreshold" evaluation_periods = "2" metric_name = "FreeableMemory" namespace = "AWS/RDS" period = "120" statistic = "Average" threshold = "10" alarm_description = "Average database freeable memory is too low, performance may be negatively impacted." dimensions = { DBInstanceIdentifier = aws_db_instance.rds_instance.id } }
Related
See also
Advertising: