如何使用Terraform在CloudWatch警报中定位特定的RDS实例?
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少
dimensions
aws_cloudwatch_metric_alarm
资源上的属性。您很可能会从中获得一个永久性的警报,从而在“数据不足”状态下。您需要添加 dbinstanceIdentsiferfier :
You're missing the
dimensions
attribute on youraws_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: