在 AWS 中缩减 Auto Scaling Group 会导致永久警报

Scaling Down Auto Scaling Group in AWS causes perpetual alarm

我目前正在使用附加到我的自动缩放组的两个缩放策略: A

  1. 调用 CloudWatch 警报时调用的扩展策略。此 CloudWatch 警报使用 CPU 利用率指标并在 CPU 超过 80% 时触发。
  2. 另一个是在调用不同的 CloudWatch 警报时调用的缩减策略。此 CloudWatch 警报使用 CPU 利用率指标并在 CPU 低于 50% 时触发。

这种方法的副作用是当我的 ASG 实例空闲时(完全缩小,没有处理发生)我的 ASG 处于警报状态。

有没有办法进行不同的设置,使我的 ASG 不处于持续警报状态?

以下是我的 CloudFormation 模板中的这些警报的一部分:

"ScaleUpPolicy" : {
  "Type" : "AWS::AutoScaling::ScalingPolicy",
  "Properties" : {
    "AdjustmentType" : "ChangeInCapacity",
    "AutoScalingGroupName" : { "Ref" : "WebApplicationASG" },
    "Cooldown" : "1",
    "ScalingAdjustment" : "1"
  }
},
"CPUAlarmHigh": {
  "Type": "AWS::CloudWatch::Alarm",
  "Properties": {
    "EvaluationPeriods": "1",
    "Statistic": "Average",
    "Threshold": "80",
    "AlarmDescription": "Alarm if CPU too high or metric disappears indicating instance is down",
    "Period": "60",
    "AlarmActions": [ { "Ref": "ScaleUpPolicy" } ],
    "Namespace": "AWS/EC2",
    "Dimensions": [ {
      "Name": "AutoScalingGroupName",
      "Value": { "Ref": "WebApplicationASG" }
    } ],
    "ComparisonOperator": "GreaterThanThreshold",
    "MetricName": "CPUUtilization"
  }
},
"ScaleDownPolicy" : {
  "Type" : "AWS::AutoScaling::ScalingPolicy",
  "Properties" : {
    "AdjustmentType" : "ChangeInCapacity",
    "AutoScalingGroupName" : { "Ref" : "WebApplicationASG" },
    "Cooldown" : "1",
    "ScalingAdjustment" : "-1"
  }
},
"CPUAlarmLow": {
  "Type": "AWS::CloudWatch::Alarm",
  "Properties": {
    "EvaluationPeriods": "1",
    "Statistic": "Average",
    "Threshold": "50",
    "AlarmDescription": "Alarm if CPU is low, causing scale down",
    "Period": "60",
    "AlarmActions": [ { "Ref": "ScaleDownPolicy" } ],
    "Namespace": "AWS/EC2",
    "Dimensions": [ {
      "Name": "AutoScalingGroupName",
      "Value": { "Ref": "WebApplicationASG" }
    } ],
    "ComparisonOperator": "LessThanThreshold",
    "MetricName": "CPUUtilization"
  }
},

这是正常的预期行为。

在警报状态下有一个指标不是问题 - 请记住,触发事件的是警报状态的变化。因此,大概一旦您的放大触发器进入警报状态,缩小规模就会退出警报。然后当指标下降时,它会回到警报状态,并触发缩减事件。

您可以通过单击 "Hide Autoscaling Alarms" 复选框在控制台中隐藏它们。

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/hide-autoscaling-alarms.html

仍然不理想,但聊胜于无。