是否可以使用Elastic Beanstlak添加多个自动缩放策略

时间:2016-10-28 13:12:18

标签: amazon-web-services elastic-beanstalk

我们已经使用ElasticBeanstalk实现了部署生命周期的自动化,我们很高兴除了一件事;我们希望有多个自动扩展策略,如CPU使用率和网络流量,但似乎我们只需要选择其中一个指标。

我们目前正在使用名为eb_deployer的开源工具,它支持以下链接中列出的配置:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalingtrigger

据我们所知,我们只能使用aws:autoscaling:trigger

设置一个政策

我们也寻找.ebextensions但似乎.ebextension在这个问题上也有相同的限制。所以,我们想知道有没有办法在ElasticBeanstalk中使用多个自动扩展策略?

2 个答案:

答案 0 :(得分:1)

以下配置对我有用,应该放在弹性bean扩展配置文件中: 此配置完成了几项更改默认行为的操作:

  • 它禁用自动生成的警报
  • 它创建2个扩展策略:一个CPU负载,另一个基于每个目标的请求数。

  • 对于每个警报,它使用不同的评估周期进行放大和缩小,因为我希望快速放大,但是缓慢缩小。

禁用自动生成的警报:

 ######## disable the default alarms ##############
  AWSEBCloudwatchAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions: []

  AWSEBCloudwatchAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions: []
  
  
  #############   create custom policies ##################
  AutoScalingCustomScaleDownPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: {Ref: AWSEBAutoScalingGroup}
      ScalingAdjustment: -1

  AutoScalingCustomScaleUpPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: {Ref: AWSEBAutoScalingGroup}
      ScalingAdjustment: 1
 
 
 
 ############## alarms for cpu load - reusing the default policy of EB #######
   CustomScalingAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AWSEBAutoScalingScaleUpPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale up on cpu load" ]]}
      ComparisonOperator: GreaterThanThreshold
      Dimensions:
        - Name: AutoScalingGroupName
          Value: {Ref: AWSEBAutoScalingGroup}
      Statistic: Average
      Period: 60
      EvaluationPeriods: 2
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Threshold: 55

  CustomScalingAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AWSEBAutoScalingScaleDownPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale down on cpu load" ]]}
      ComparisonOperator: LessThanThreshold
      Dimensions:
        - Name: AutoScalingGroupName
          Value: {Ref: AWSEBAutoScalingGroup}
      Period: 60
      Statistic: Average
      EvaluationPeriods: 15
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Threshold: 20



 ############# alarms on request count per target ####################
 ############# using the new custom policy        ####################
  CustomScalingOnRequestCountAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AutoScalingCustomScaleDownPolicy}
      InsufficientDataActions:
        - {Ref: AWSEBAutoScalingScaleDownPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale down on request count." ]]}
      ComparisonOperator: LessThanThreshold
      Dimensions:
        - Name: LoadBalancer
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancer", "LoadBalancerFullName" ] }
        - Name: TargetGroup
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancerTargetGroup", "TargetGroupFullName" ] }
      Period: 60
      Statistic: Sum
      EvaluationPeriods: 5
      MetricName: RequestCountPerTarget
      Namespace: AWS/ApplicationELB
      Threshold: 70

  CustomScalingOnRequestCountAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AutoScalingCustomScaleUpPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale up on request count." ]]}
      ComparisonOperator: GreaterThanThreshold
      Dimensions:
        - Name: LoadBalancer
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancer", "LoadBalancerFullName" ] }
        - Name: TargetGroup
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancerTargetGroup", "TargetGroupFullName" ] }
      Period: 60
      Statistic: Sum
      EvaluationPeriods: 2
      MetricName: RequestCountPerTarget
      Namespace: AWS/ApplicationELB
      Threshold: 250

答案 1 :(得分:0)

我遇到了同样的问题,并向AWS技术支持寻求帮助。他们的回应与上面提供的@Tamar一致。我发现的唯一沮丧/烦恼是,对于“ AWS / xxx”命名空间,CloudWatch Alarms的监视时间必须为60秒或60秒的倍数。 :(对于生产环境来说,这似乎需要很长时间。

这是来自AWS的全部答案:

  1. latency-autoscalingtrigger.config
option_settings:
  aws:autoscaling:trigger:
    MeasureName: Latency
    Statistic: Average
    Unit: Seconds
    Period: '1'
    EvaluationPeriods: '1'
    UpperThreshold: '0.3'
    UpperBreachScaleIncrement: '1'
    LowerThreshold: '0.1'
    LowerBreachScaleIncrement: '-1'
  1. cpu-autoscalingtrigger.config
Mappings:
  CustomConfig:
    ScalingConfig: 
      MetricNamespace: AWS/EC2
      TriggerMeasurement: CPUUtilization
      TriggerStatistic: Average
      MeasurementPeriod: '60'
      NumCoolDownPeriods: '1'
      LowerThreshold: '30'
      UpperThreshold: '60'
      LowerBreachIncrement: '-1'
      UpperBreachIncrement: '1'

##############################################
#### Do not modify values below this line ####
##############################################

Resources:
  CustomScalingAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
      - {Ref: AutoScalingCustomScaleUpPolicy}
      AlarmDescription: ElasticBeanstalk custom scale up alarm
      ComparisonOperator: GreaterThanThreshold
      Dimensions:
      - Name: AutoScalingGroupName
        Value: {Ref: AWSEBAutoScalingGroup}
      EvaluationPeriods:
        Fn::FindInMap: [CustomConfig, ScalingConfig, NumCoolDownPeriods]
      MetricName:
        Fn::FindInMap: [CustomConfig, ScalingConfig, TriggerMeasurement]
      Namespace:
        Fn::FindInMap: [CustomConfig, ScalingConfig, MetricNamespace]
      Period:
        Fn::FindInMap: [CustomConfig, ScalingConfig, MeasurementPeriod]
      Statistic:
        Fn::FindInMap: [CustomConfig, ScalingConfig, TriggerStatistic]
      Threshold:
        Fn::FindInMap: [CustomConfig, ScalingConfig, UpperThreshold]
  CustomScalingAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
      - {Ref: AutoScalingCustomScaleDownPolicy}
      AlarmDescription: ElasticBeanstalk custom scale down alarm
      ComparisonOperator: LessThanThreshold
      Dimensions:
      - Name: AutoScalingGroupName
        Value: {Ref: AWSEBAutoScalingGroup}
      EvaluationPeriods:
        Fn::FindInMap: [CustomConfig, ScalingConfig, NumCoolDownPeriods]
      MetricName:
        Fn::FindInMap: [CustomConfig, ScalingConfig, TriggerMeasurement]
      Namespace:
        Fn::FindInMap: [CustomConfig, ScalingConfig, MetricNamespace]
      Period:
        Fn::FindInMap: [CustomConfig, ScalingConfig, MeasurementPeriod]
      Statistic:
        Fn::FindInMap: [CustomConfig, ScalingConfig, TriggerStatistic]
      Threshold:
        Fn::FindInMap: [CustomConfig, ScalingConfig, LowerThreshold]
  AutoScalingCustomScaleDownPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: {Ref: AWSEBAutoScalingGroup}
      ScalingAdjustment:
        Fn::FindInMap: [CustomConfig, ScalingConfig, LowerBreachIncrement]
  AutoScalingCustomScaleUpPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: {Ref: AWSEBAutoScalingGroup}
      ScalingAdjustment:
        Fn::FindInMap: [CustomConfig, ScalingConfig, UpperBreachIncrement]