在RDS群集中的所有实例上创建CloudWatch警报

时间:2018-08-16 21:53:02

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

我有一个具有2个实例的RDS Aurora集群,一个读取器和一个写入器。

我在DatabaseConnections上创建了一个维度为DBClusterIdentifier的CloudWatch警报。

但是警报仅适用于一个实例(写者)。如果读取器超过阈值,则不会触发警报。

如果任何RDS实例超过阈值,如何获取警报以触发。

这是我的代码:

resource "aws_cloudwatch_metric_alarm" "rds-connection-count-alarm" {
  alarm_name = "rds-connection-count-alarm"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods = "1"
  metric_name = "DatabaseConnections"
  namespace = "AWS/RDS"
  period = "60"
  statistic = "Maximum"
  threshold = "1000" # max 2000 for db.r4.xlarge rds instances

  dimensions {
    DBClusterIdentifier = "${aws_rds_cluster.my_rds_cluster.id}"
  }

  alarm_description = "Alerts Slack if the DB connection count exceeds 1000"
  alarm_actions = ["${data.aws_sns_topic.notification_topic.arn}"]
  ok_actions = ["${data.aws_sns_topic.notification_topic.arn}"]
  insufficient_data_actions = []

  lifecycle {
    create_before_destroy = true
  }
}

1 个答案:

答案 0 :(得分:0)

我知道这已经很老了,但是DBClusterIdentifier无法使用正则表达式,因此不幸的是,您必须为每个实例发出警报。有点烂。

因此,我们不使用CloudWatch,而是根据使用情况使用Datadog和/或Newrelic。