我目前正在将AWS的Elastic Beanstalk工作者用于我的队列,可用于触发自动扩展的指标非常通用(CPU,Net in,Net out等)。
我很想知道是否可以根据连接到worker的队列的状态使用触发器 - 特别是根据过去X分钟内队列中可用消息的平均数量添加或删除实例?
答案 0 :(得分:1)
如果您正在使用SQS,这是非常可能的并且建议使用,如果我没记错的话,这是架构课程中的一个示例。
下面是一个例子的进一步信息 https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-using-sqs-queue.html
答案 1 :(得分:0)
由于这是此类搜索的第一个热门,我想用答案进行更新。 AWS现在有一个示例.ebextensions配置可以完全按照您的要求执行:
转载于此:
Resources:
AWSEBCloudwatchAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions: []
AWSEBCloudwatchAlarmLow:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions: []
QueueDepthAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: "Alarm if queue depth grows beyond 20 messages"
Namespace: "AWS/SQS"
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: { "Fn::GetAtt": ["AWSEBWorkerQueue", "QueueName"] }
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 20
ComparisonOperator: GreaterThanThreshold
AlarmActions:
- Ref: AWSEBAutoScalingScaleUpPolicy
QueueDepthAlarmLow:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: "Alarm if queue depth is less than 5 messages"
Namespace: "AWS/SQS"
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: { "Fn::GetAtt": ["AWSEBWorkerQueue", "QueueName"] }
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 5
ComparisonOperator: LessThanThreshold
AlarmActions:
- Ref: AWSEBAutoScalingScaleDownPolicy
基本上它会删除默认警报并根据邮件大小创建新警报。我已经测试了这个配置,如果您使用ElasticBeanstalk中的自动生成队列,它会按原样运行,但是如果您指定一个预先存在的队列,它就不会。您可以在此脚本中对队列名称进行硬编码,也可以检索URL并对其进行操作以获取名称。我不是CloudFormation的专家,所以可能有更好的方法来做到这一点,但这就是我想出的:
Resources:
# make the default alarms do nothing (I believe)
AWSEBCloudwatchAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions: []
AWSEBCloudwatchAlarmLow:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions: []
# set the High alarm
QueueDepthAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: "Alarm if queue depth grows beyond 50 messages"
Namespace: "AWS/SQS"
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value:
"Fn::Select":
- 4
- "Fn::Split":
- '/'
- "Fn::GetOptionSetting":
Namespace: "aws:elasticbeanstalk:sqsd"
OptionName: "WorkerQueueURL"
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 50
ComparisonOperator: GreaterThanThreshold
AlarmActions:
- Ref: AWSEBAutoScalingScaleUpPolicy
# set the Low alarm
QueueDepthAlarmLow:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: "Alarm if queue depth is less than 5 messages"
Namespace: "AWS/SQS"
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value:
"Fn::Select":
- 4
- "Fn::Split":
- '/'
- "Fn::GetOptionSetting":
Namespace: "aws:elasticbeanstalk:sqsd"
OptionName: "WorkerQueueURL"
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 5
ComparisonOperator: LessThanThreshold
AlarmActions:
- Ref: AWSEBAutoScalingScaleDownPolicy