【问题标题】:Why doesn't an aws_cloudwatch_metrics_alarm for RDS DBInstance show up in console?为什么 RDS DBInstance 的 aws_cloudwatch_metrics_alarm 没有显示在控制台中?
【发布时间】:2019-01-14 20:57:09
【问题描述】:

我正在尝试为具有 Terraform 0.11.7 和 AWS 提供商 1.30 版本的 RDS 数据库添加 CloudWatch 警报。

我创建了一个主题。

resource "aws_sns_topic" "alarm" {
  name                    = "${var.cluster_name}-alarms-topic"
  delivery_policy         = <<-EOF
                            {
                              "http": {
                                "defaultHealthyRetryPolicy": {
                                  "minDelayTarget": 20,
                                  "maxDelayTarget": 20,
                                  "numRetries": 3,
                                  "numMaxDelayRetries": 0,
                                  "numNoDelayRetries": 0,
                                  "numMinDelayRetries": 0,
                                  "backoffFunction": "linear"
                                },
                                "disableSubscriptionOverrides": false,
                                "defaultThrottlePolicy": {
                                  "maxReceivesPerSecond": 1
                                }
                              }
                            }
                            EOF

  provisioner "local-exec" {
    command = "aws sns subscribe --topic-arn ${self.arn} --protocol email --notification-endpoint ${var.alerts_email}"
  }
}

我已经创建了一个 RDS 数据库。

resource "aws_db_instance" "database" {
  identifier                = "${var.cluster_name}"
  engine                    = "${var.engine}"
  engine_version            = "${var.engine_version}"
  allocated_storage         = "${var.db_size_gb}"
  instance_class            = "${var.instance_type}"
  name                      = "postgres"
  username                  = "postgres"
  password                  = "postgres"
  publicly_accessible       = false
  skip_final_snapshot       = true
  tags                      = "${var.tags}"
  vpc_security_group_ids    = ["${aws_security_group.database.id}"]
}

我创建了一个警报指标:

resource "aws_cloudwatch_metric_alarm" "database-storage-low-alarm" {
  alarm_name                = "database-storage-low-alarm"
  alarm_description         = "This metric monitors database storage dipping below threshold"
  alarm_actions             = ["${var.alerts_arn}"]
  comparison_operator       = "LessThanThreshold"
  threshold                 = "20"
  evaluation_periods        = "2"
  metric_name               = "FreeStorageSpace"
  namespace                 = "RDS"
  period                    = "120"
  statistic                 = "Average"

  dimensions {
    DBInstanceIdentifier    = "${aws_db_instance.database.id}"
  }
}

我可以应用配置,查询该资源的状态会显示它的存在:

$ terraform state show module.staging.module.usw2.module.db.aws_cloudwatch_metric_alarm.database-storage-low-alarm
id                                    = database-storage-low-alarm
actions_enabled                       = true
alarm_actions.#                       = 1
alarm_actions.3493004098              = arn:aws:sns:us-west-2:114416042199:recs-api-staging-alarms-topic
alarm_description                     = This metric monitors database storage dipping below threshold
alarm_name                            = database-storage-low-alarm
comparison_operator                   = LessThanThreshold
datapoints_to_alarm                   = 0
dimensions.%                          = 1
dimensions.DBInstanceIdentifier       = recs-api-staging
evaluate_low_sample_count_percentiles =
evaluation_periods                    = 2
extended_statistic                    =
insufficient_data_actions.#           = 0
metric_name                           = FreeStorageSpace
namespace                             = RDS
ok_actions.#                          = 0
period                                = 120
statistic                             = Average
threshold                             = 20
treat_missing_data                    = missing
unit                                  =

当我为创建的 RDS 数据库打开管理控制台时,CloudWatch 警报似乎不存在。

有人知道为什么创建的资源没有出现在控制台中吗?让我感到震惊的一件事是返回状态中的dimensions.DBInstanceIdentifier = recs-api-staging。这是正确的,还是应该改为 ARN?

非常感谢!

【问题讨论】:

  • 没有出现在哪个控制台? Cloudwatch 警报控制台?如果您尝试使用 CLI 来描述它会发生什么?
  • 抱歉,RDS 实例的 AWS 管理控制台 UI。但是,我刚刚发现了问题。我忽略了在命名空间前加上“AWS/”。命名空间“AWS/RDS”按预期工作。
  • 您应该考虑关闭问题,因为它是一个微不足道的答案,或者至少是自己回答的解决方案。

标签: amazon-web-services amazon-rds terraform amazon-cloudwatch amazon-cloudwatch-metrics


【解决方案1】:

解决方案是修复命名空间。确保使用命名空间“AWS/RDS”而不是 RDS。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多