在数据不足时自动缩放

问题描述

我们为ECS服务配置了自动缩放功能。自动缩放的工作流程应如下所示:

  • 如果在1分钟内我们收到超过10个值,则需要按比例放大
  • 等待10分钟
  • 如果没有值,我们需要按比例缩小

按比例放大效果完美,但按比例缩小完全无效。我们得到这个:

Failed to execute action arn:aws:autoscaling:eu-central-1:BLA-BLA-BLA-fargate-scale-down. Received error: ""

可能是因为在resource "aws_appautoscaling_policy" "down"的Terraform中,我们具有以下内容:

    step_adjustment {
      metric_interval_lower_bound = ""
      metric_interval_upper_bound = 0
      scaling_adjustment          = -100
    }

,它期望为“ 0”而不是没有数据。

resource "aws_cloudwatch_metric_alarm" "cloudwatch_metric_alarm_down"中:

  treat_missing_data = "breaching"

  insufficient_data_actions = [aws_appautoscaling_policy.down.arn]

对此有什么解决方案吗?除非每分钟手动发送“ 0”。

解决方法

解决方案是:

resource "aws_cloudwatch_metric_alarm" "cloudwatch_metric_alarm_down" {
  alarm_name          = "${local.name}-ecs-alarm-down"
  comparison_operator = "LessThanOrEqualToThreshold"
  evaluation_periods  = var.evaluation_periods_down
  threshold           = var.downscale_threshold

  metric_query {
    id          = "e1"
    expression  = "FILL(m1,0)"
    label       = "0 if NoData"
    return_data = "true"
  }

  metric_query {
    id = "m1"
    metric {
      metric_name = var.metric_name
      namespace   = var.env_name
      period      = "60"
      stat        = var.metric_statistic
    }
  }

  alarm_actions = [aws_appautoscaling_policy.down.arn]

  depends_on = [aws_appautoscaling_policy.down]
}

有关FILL()的更多信息,请点击此处https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html#metric-math-syntax-functions-list

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...