Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

amazon web services - How do I write a terraform code to create an aws_cloudwatch_metric_alarm for too many db connections?

In AWS CloudWatch I can create an alarm that will alert me if my database has too many connections:

enter image description here

And I have used terraform to create another alarm ...

resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high" {
  alarm_name          = "cpu_utilization_too_high"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "1"
  metric_name         = "CPUUtilization"
  namespace           = "AWS/RDS"
  period              = "600"
  statistic           = "Average"
  threshold           = var.cpu_utilization_threshold
  alarm_description   = "Average database CPU utilization over last 10 minutes too high"
  alarm_actions       = [aws_sns_topic.topic.arn]
  ok_actions          = [aws_sns_topic.topic.arn]

  dimensions = {
    DBInstanceIdentifier = "${var.db_instance_id}"
  }
}

Now I want to use terraform to create an alarm that will alert me to my database connections but I do not know what to set metric_name to ...

  metric_name         = ???TooMuchConnectingtoDataBase???

I have looked at the terraform documentation but it doesn't document what do use for the metric_name. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to the doc,

resource "aws_cloudwatch_metric_alarm" "too_many_db_connections" {
  alarm_name          = "too_many_db_connections"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "1"
  metric_name         = "DatabaseConnections"
  namespace           = "AWS/RDS"
  period              = "600"
  statistic           = "Average"
  threshold           = var.db_connection_threshold
  alarm_description   = "Average db connections over last 10 minutes is too high"
  alarm_actions       = [aws_sns_topic.topic.arn]
  ok_actions          = [aws_sns_topic.topic.arn]

  dimensions = {
    DBInstanceIdentifier = "${var.db_instance_id}"
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...