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

发布于 2025-02-13 23:22:25 字数 1076 浏览 1 评论 0原文

我正在尝试使用Terraform在RDS实例上创建一个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来定位Speicific实例?

I'm trying to create a CloudWatch alarm for CPUUtilization on an RDS Instance using terraform. I am able to get an alarm working but am unsure which RDS instance in particular this is monitoring. Hence I would like to be able to choose a specific RDS instance to monitor.

The code below works in as far as it builds a resource for an alarm, which when triggered sends an email notification via SNS topic.

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  = "*****"
}

Would this alarm just monitor all of the instances within this AWS account? How am I able to target a speicific instance based on an instance ID for example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您缺少dimensions aws_cloudwatch_metric_alarm资源上的属性。您很可能会从中获得一个永久性的警报,从而在“数据不足”状态下。

您需要添加 dbinstanceIdentsiferfier

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

   dimensions = {
      DBInstanceIdentifier = "your_db_instance_id"
   }
}

You're missing the dimensions attribute on your aws_cloudwatch_metric_alarm resource. You would most likely get an alarm that is perpetually in "Insufficient Data" status from that.

You need to add the DBInstanceIdentifier dimension to the alarm, like:

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

   dimensions = {
      DBInstanceIdentifier = "your_db_instance_id"
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文