我通过将扩展策略与触发策略评估的关联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"