简体   繁体   中英

Terraform for an AWS CloudWatch Alarm for ApproximateNumberOfMessagesVisible Threshold

So I'm trying to create a Cloudwatch alarm that will reach the 'alarm' state when the 'ApproximateNumberOfMessagesVisible' metric exceeds a given threshold. I've tinkered with this a lot, and I can't get it to reach the 'alarm' state, even though the number of messages visible in the queue is definitely over the threshold. I might have gotten the dimension wrong or something, or it might not be able to poll the queue somehow... But I'm not sure how to troubleshoot it, because everything looks more or less correct..? I'd really appreciate some help.

I'm also not quite sure on the treat_missing_data field... Is there a way to set this to poll the queue?

Here is my Terraform. The autoscaling policies are irrelevant for this question for now.

resource "aws_cloudwatch_metric_alarm" "queue-depth-alarm-2" {
 alarm_name          = "queue-depth-alarm"
 comparison_operator = "GreaterThanOrEqualToThreshold"
 evaluation_periods  = "1"
 metric_name         = "ApproximateNumberOfMessagesVisible"
 namespace           = "AWS/SQS"
 period              = "60"
 statistic           = "Average"
 threshold           = "5000"
 treat_missing_data = "notBreaching"

 dimensions = {
 QueueName            = "${aws_sqs_queue.my_sqs_inbound_all.name}"
 AutoScalingGroupName = "${aws_autoscaling_group.myapp.name}"
 }

alarm_description = "This metric monitors queue depth and scales up or down accordingly."
 alarm_actions     = ["${aws_autoscaling_policy.myapp-scaleup-policy.arn}", "${aws_sns_topic.myqueue_depth_alert_topic.arn}"]
 ok_actions        = ["${aws_autoscaling_policy.myapp-scaledown-policy.arn}"]
}

This is how the alarm looks in the CloudWatch Console: https://i.stack.imgur.com/9Jqv8.png

我认为这里不需要 Autoscaling 组。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM