为 AWS Fargate 设置 Cloudwatch 警报高阈值和低阈值

Set the Cloudwatch Alarm High and Low thresholds for AWS Fargate

我已经创建了一个自动缩放目标和一个附加到它的策略。

AutoScalingPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: !Join ['', [!Ref ServiceName, auto-scaling-policy]]
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref AutoScalingTarget
      TargetTrackingScalingPolicyConfiguration:
        PredefinedMetricSpecification:
          PredefinedMetricType: ECSServiceAverageCPUUtilization
        ScaleInCooldown: 10
        ScaleOutCooldown: 10
        # Keep things at or lower than 50% CPU utilization, for example
        TargetValue: !Ref AutoScalingTargetValue

这是在创建 cloudwatch 警报:

高: 3 datapoints within 3 minutes

低: 15 datapoints within 15 minutes

我想将其自定义为:

高: 1 datapoint within 1 minute

低: 1 datapoint within 1 minute

我可以从 AWS 控制台手动执行此操作。但是,正在努力寻找使用 cloudformation 模板执行相同操作的方法。

目标跟踪实际上没有"high"和"low"阈值。通过目标跟踪,您可以设置目标 CPU 利用率百分比值,并尝试将其保持在该值,自动缩放会自动上下更新任务数,以尝试将 CPU 利用率保持在该值。

如果你想要更细粒度的控制,你需要使用 "step scaling policy"。这允许您设置特定值,例如 "if CPU percent is between 0 and 10% over my target of 50% then increase by 1" 和 "if CPU percent is between 10% and 20% over my target of 50% then increase by 2".

您可以在此处的可下载开源 CloudFormation 模板中看到此类步进扩展策略的示例:https://containersonaws.com/architecture/autoscaling-service-containers/直接包含在该答案中太长了,但您可以使用这些官方 AWS 示例模板作为步进扩展策略的起点。

虽然目标跟踪允许您指定单个值,但实际上在 CloudWatch 中会变成两个警报。 High 警报将是 YourMetric > YourTargetValue for X datapoints for Y minutesLow 警报将是 YourMetric < SomeValue for A datapoints for B minutes