如何使用 Terraform 在 CloudWatch 警报中定位特定 RDS 实例?

问题描述 投票:0回答:2

我正在尝试使用 terraform 在 RDS 实例上为 CPUUtilization 创建 CloudWatch 警报。我能够让警报正常工作,但不确定它正在监视哪个 RDS 实例。因此我希望能够选择一个特定的 RDS 实例来监控。

下面的代码可以为警报构建资源,当触发该资源时,会通过 SNS 主题发送电子邮件通知。

resource "aws_cloudwatch_metric_alarm" "CPUUtilization" {
  alarm_name                = "test-cpu-alarm"
  comparison_operator       = "GreaterThanOrEqualToThreshold"
  evaluation_periods        = "5"
  metric_name               = "CPUUtilization"
  namespace                 = "AWS/RDS"
  period                    = "30"
  statistic                 = "Maximum"
  threshold                 = "50"
  alarm_description         = "This metric monitors RDS CPU utilization"
  alarm_actions             = [aws_sns_topic.test_cloudwatch_updates.arn]
  insufficient_data_actions = []
}

resource "aws_sns_topic" "test_cloudwatch_updates" {
  name = "test-cloudwatch-notifications"
}

resource "aws_sns_topic_subscription" "cloudwatch_email_sub" {
  topic_arn = aws_sns_topic.test_cloudwatch_updates.arn
  protocol  = "email"
  endpoint  = "*****"
}

此警报是否仅监控此 AWS 账户内的所有实例?例如,我如何能够根据实例 ID 定位特定实例?

amazon-web-services terraform amazon-cloudwatch terraform-provider-aws cloudwatch-alarms
2个回答
2
投票

您的

dimensions
资源上缺少
aws_cloudwatch_metric_alarm
属性。您很可能会收到一个永久处于“数据不足”状态的警报。

您需要将 DBInstanceIdentifier 维度添加到警报中,例如:

resource "aws_cloudwatch_metric_alarm" "CPUUtilization" {
   # your other alarm attributes

   dimensions = {
      DBInstanceIdentifier = "your_db_instance_id"
   }
}

0
投票

类似的问题,但如何在 Terraform 中为 RDS 和 RDS 只读副本数据库创建 CW 警报?如果我只想使用一个资源创建块?

© www.soinside.com 2019 - 2024. All rights reserved.