8

我们根据负载均衡器 RequestCount 指标使用云形成进行自动缩放。目前,如果请求增加到 1500 1 分钟,我们会扩展一个实例(每个实例每分钟可以处理 1500 个请求)。问题是,因为自动缩放组不断检查 RequestCount 并在请求计数大于 1500 1 分钟时添加一个新实例。但这不是必需的,因为我现在有 2 个可以处理 3000 个请求的实例。每分钟。是否有任何工具可以定制矩阵?即,如果添加新实例,则扩展策略将更改为 3000 req。

示例场景:

  1. 最初有 1 个 ELB,1 个连接到 ELB 的 tomcat 实例(每分钟可以处理 1500 个请求)。
  2. 1 个云手表,如果需要,可以采取扩大策略的行动。ELB 的计数增加到 1500 分钟。
  3. 当前,ELB 上的请求负载为 1500,持续 1 分钟。现在要求。负载增加到 1700 分钟。因此它将在 ELB 上附加一个新的 tomcat 实例。所以我有 2 个实例可以处理 3000 个请求。分钟。
  4. 但是现在云手表有什么问题仍然检查req。依靠 ELB,如果需要。最小负载为 1700。它将添加一个不需要的新 tomcat 实例。

我怎样才能摆脱这个问题?

4

3 回答 3

4

您要做的是使用负载均衡器的平均值。您可以有不同类型的指标。总和、平均值、最小值、最大值和样本。如果您选择平均,它将为您提供负载均衡器下所有实例的平均值。因此,只有当您组中的所有服务器都达到每分钟 1500 个请求时,它才会触发新的实例启动。

类型的快速描述:

  • 平均值 - 负载均衡器的平均值
  • Sum - 请求的总数(例如:3000)
  • 最大值 - 任何服务器的最大请求数(因为它可能不完全平衡)
  • 最小值 - 任何服务器的最小请求数(因为它可能不完全平衡)
  • 示例 - 用于计算平均值的服务器数量(基本上是负载均衡器上有多少台服务器)

您也可以创建自己的自定义指标,但您需要创建一个应用程序来告诉亚马逊这些值是什么。使用 cloud watch api,您可以轻松创建自己的。看看这里http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/Welcome.html?r=1540

于 2012-04-09T14:43:48.930 回答
1

正如 dsummersl 所说,RequestCount不能直接与平均指标一起使用。

我在这里找到了一些解决方法。基本上,它们会告诉您定义一个自定义 CloudWatch 指标,以便您可以检测您的实例以发出它们正在接收的请求数量。

为此,您需要收集来自每个实例的请求计数并使用put-metric-data将其发送到 cloudwatch ,或者创建一个ebextension以便 EBS 为您完成(我认为这是最简单的方法)。

然后,您可以根据该自定义指标将 Auto Scaling 设置为向上/向下扩展。

希望能帮助到你。

于 2016-10-19T13:19:47.267 回答
1

我通过将扩展策略与触发策略评估的关联Cloudwatch 警报RequestCount一起应用扩展策略,从而根据工作进行扩展。下面是我在 ElasticBeanstalk 应用程序中使用的 cloudformation 模板:

   RequestCountScalingAlarmLt2000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions:
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when Request Count < 2000"
       AlarmName: {"Fn::Join": ["-", ["Scale when Request Count < 2000", { "Ref":"AWSEBEnvironmentName" }]]}
       ComparisonOperator: LessThanThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 2000
   RequestCountScalingAlarmGt2000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions:
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when 2000 < Request Count < 20000"
       AlarmName: "Scale when Request 2000 < Count < 20000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 2000
   RequestCountScalingAlarmGt20000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions:
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when 20000 < Request Count < 30000"
       AlarmName: "Scale when 20000 < Request Count < 30000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 20000
   RequestCountScalingAlarmGt30000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions:
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when 30000 < Request Count < 40000"
       AlarmName: "Scale when 30000 < Request Count < 40000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 30000
   RequestCountScalingAlarmGt40000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions::
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when 40000 < Request Count < 50000"
       AlarmName: "Scale when 40000 < Request Count < 50000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 40000
   RequestCountScalingAlarmGt50000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions:
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when 50000 < Request Count < 60000"
       AlarmName: "Scale when 50000 < Request Count < 60000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 50000
   RequestCountScalingAlarmGt60000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions::
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when 60000 < Request Count < 70000"
       AlarmName: "Scale when 60000 < Request Count < 70000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 60000
   RequestCountScalingAlarmGt70000:
     Type: "AWS::CloudWatch::Alarm"
     Properties:
       ActionsEnabled: true
       AlarmActions:
         - Ref: RequestCountScalingPolicy
       OKActions:
         - Ref: RequestCountScalingPolicy
       AlarmDescription: "Scale when Request Count >= 70000"
       AlarmName: "Scale when Request Count >= 70000"
       ComparisonOperator: GreaterThanOrEqualToThreshold
       Dimensions:
         - Name: LoadBalancerName
           Value:
             Ref: AWSEBLoadBalancer
       EvaluationPeriods: "1"
       MetricName: RequestCount
       Namespace: AWS/ELB
       Period: "300"
       Statistic: Sum
       Threshold: 70000
   RequestCountScalingPolicy:
     Type: "AWS::AutoScaling::ScalingPolicy"
     Properties:
       AutoScalingGroupName:
         Ref: "AWSEBAutoScalingGroup"
       AdjustmentType: "ExactCapacity"
       PolicyType: "StepScaling"
       EstimatedInstanceWarmup: 120
       StepAdjustments:
         -
           MetricIntervalLowerBound: "0"
           MetricIntervalUpperBound: "2000"
           ScalingAdjustment: "1"
         -
           MetricIntervalLowerBound: "2000"
           MetricIntervalUpperBound: "20000"
           ScalingAdjustment: "2"
         -
           MetricIntervalLowerBound: "20000"
           MetricIntervalUpperBound: "30000"
           ScalingAdjustment: "3"
         -
           MetricIntervalLowerBound: "30000"
           MetricIntervalUpperBound: "40000"
           ScalingAdjustment: "4"
         -
           MetricIntervalLowerBound: "40000"
           MetricIntervalUpperBound: "50000"
           ScalingAdjustment: "5"
         -
           MetricIntervalLowerBound: "50000"
           MetricIntervalUpperBound: "60000"
           ScalingAdjustment: "6"
         -
           MetricIntervalLowerBound: "60000"
           MetricIntervalUpperBound: "70000"
           ScalingAdjustment: "7"
         -
           MetricIntervalLowerBound: "70000"
           ScalingAdjustment: "8"
于 2017-03-30T09:49:27.937 回答