gpt4 book ai didi

amazon-web-services - 是否可以使用 Elastic Beanstalk 添加多个自动扩展策略

转载 作者:行者123 更新时间:2023-12-04 15:31:41 24 4
gpt4 key购买 nike

我们使用 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 中使用多个自动缩放策略?

最佳答案

以下配置对我有用,应该放在弹性 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

    关于amazon-web-services - 是否可以使用 Elastic Beanstalk 添加多个自动扩展策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40305869/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com