2
votes

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

1
Does the alarm config seem right in the CloudWatch console? The above code looks fine but it's hard to say what's wrong here without actually seeing your queue. Are you able to create an alarm via the CloudWatch console that does trigger how you want? - ydaetskcoR
I've edited the question to include a picture of the state of the alarm in the console :). I'm not able to create an alarm in the actual console because it won't show me my ASGs in the dropdown, which is weird because they do exist... - RhythmOfRiora
Why are you adding Auto Scaling Group as a dimension? Pretty sure SQS doesn’t care about Auto Scaling Groups. The only dimension should be the queue name. - myron-semack
^ This was the problem! Thank you so so much!!! - RhythmOfRiora

1 Answers

0
votes

I think Autoscaling group is not needed here.