根据SQS队列大小自动缩放 [英] Autoscale based on SQS queue size

查看:122
本文介绍了根据SQS队列大小自动缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这些命令放在一起以根据SQS队列大小自动缩放EC2实例.我已经运行了所有命令,并且队列中只有10条消息,并且尚未启动单个实例.

I have put together these commands to autoscale EC2 instances based on SQS queue size. I have run all commands and my queue is at 10 messages and a single instance hasn't been launched.

我试图弄清楚,我的cloudwatch警报正在收听哪些SQS队列?还要感谢任何有助于识别issus的帮助!

I am trying to figure out, what SQS queue my cloudwatch alarms are listening to? Also any help to indentify the issus is appreciated!

### Create Autoscaling Policy ###

aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id ami-551c6d30 --instance-type m1.small

aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-configuration-name my-lc --availability-zones "us-east-1a" "us-east-1c" --max-size 10 --min-size 0 --desired-capacity 0

# Scale up policy
aws autoscaling put-scaling-policy --policy-name my-sqs-scaleout-policy --auto-scaling-group-name my-asg --scaling-adjustment 1 --adjustment-type ChangeInCapacity

# Scale down policy
aws autoscaling put-scaling-policy --policy-name my-sqs-scalein-policy --auto-scaling-group-name my-asg --scaling-adjustment -1 --adjustment-type ChangeInCapacity

# Alarm to scale up
aws cloudwatch put-metric-alarm --alarm-name AddCapacityToProcessQueue --metric-name ApproximateNumberOfMessagesVisible --namespace "AWS/SQS" --statistic Average --period 120 --threshold 3 --comparison-operator GreaterThanOrEqualToThreshold --dimensions Name=QueueName,Value=my-queue --evaluation-periods 2 --alarm-actions arn:aws:autoscaling:us-east-1:850082592395:scalingPolicy:6408b62d-9363-4252-a88c-5ffab08a8cb5:autoScalingGroupName/my-asg:policyName/my-sqs-scaleout-policy

# Alarm to scale down
aws cloudwatch put-metric-alarm --alarm-name RemoveCapacityFromProcessQueue --metric-name ApproximateNumberOfMessagesVisible --namespace "AWS/SQS" --statistic Average --period 300 --threshold 1 --comparison-operator LessThanOrEqualToThreshold --dimensions Name=QueueName,Value=my-queue --evaluation-periods 2 --alarm-actions arn:aws:autoscaling:us-east-1:850082592395:scalingPolicy:4771ea64-2ebf-45ef-9328-50e058dc68b7:autoScalingGroupName/my-asg:policyName/my-sqs-scalein-policy

# Verify cloudwatch alarms
aws cloudwatch describe-alarms --alarm-names AddCapacityToProcessQueue RemoveCapacityFromProcessQueue

# Verify scaling policy
aws autoscaling describe-policies --auto-scaling-group-name my-asg

# Verify instances autoscaled
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name my-asg

推荐答案

AWS文档指出:

Amazon Simple Queue Service每5分钟将数据发送到CloudWatch.

Amazon Simple Queue Service sends data to CloudWatch every 5 minutes.

此外,您还指定了多个时间段内的平均值"指标.因此,将需要5分钟的时间才能将Amazon SQS指标发送到Amazon CloudWatch.

Additionally, you have specified an Average metric over several periods of time. Therefore, it will require several 5-minute periods to send Amazon SQS metrics to Amazon CloudWatch.

度量标准周期(120秒)太短而无法接收来自SQS的多个更新,因此可能导致INSUFFICIENT_DATA错误.

It's possible that the metric period (120 seconds) is too short to receive multiple updates from SQS, therefore causing INSUFFICIENT_DATA errors.

首先尝试使警报通过Maximum设置触发并按时间段播放.成功触发警报后,请尝试使用阈值来获得所需的行为.

Start by trying to get the Alarm to trigger with a Maximum setting and play with the time periods. Once the Alarm is successfully triggering, play with the thresholds to get the desired behaviour.

这篇关于根据SQS队列大小自动缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆