7
resource "azurerm_monitor_autoscale_setting" "test" {
  name                = "AutoscaleSetting"
  resource_group_name = "${azurerm_resource_group.main.name}"
  location            = "${azurerm_resource_group.main.location}"
  target_resource_id  = "${azurerm_app_service_plan.main.id}"

 profile {
name = "defaultProfile"

capacity {
  default = 1
  minimum = 1
  maximum = 10
}

rule {
  metric_trigger {
    metric_name        = "Percentage CPU"
    metric_resource_id = "${azurerm_app_service_plan.main.id}"
    time_grain         = "PT1M"
    statistic          = "Average"
    time_window        = "PT5M"
    time_aggregation   = "Average"
    operator           = "GreaterThan"
    threshold          = 80
  }

  scale_action {
    direction = "Increase"
    type      = "ChangeCount"
    value     = "1"
    cooldown  = "PT1M"
  }
}

rule {
  metric_trigger {
    metric_name        = "Percentage CPU"
    metric_resource_id = "${azurerm_app_service_plan.main.id}"
    time_grain         = "PT1M"
    statistic          = "Average"
    time_window        = "PT5M"
    time_aggregation   = "Average"
    operator           = "LessThan"
    threshold          = 80
  }

  scale_action {
    direction = "Decrease"
    type      = "ChangeCount"
    value     = "1"
    cooldown  = "PT1M"
  }
}}   

我尝试在 azure 上的 terraform 中设置自动缩放规则。这样做时会引发此错误。请帮忙。这个错误是什么?如何解决这个错误?

错误:创建自动缩放设置“AutoscaleSetting”(资源组“sm-prod-resources”)时出错:insights.AutoscaleSettingsClient#CreateOrUpdate:响应请求失败:StatusCode=400 - 原始错误:autorest/azure:服务返回错误。Status=400 Code="UnsupportedMetric" Message="抛出了 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' 类型的异常。"

4

1 回答 1

11

该错误表明它是UnsupportedMetric。根据 Terraform 中的文档,它是这样描述的:

metric_name -(必需)定义规则监控的指标的名称,例如虚拟机规模集的百分比 CPU 和应用服务计划的 CpuPercentage。

我认为这只是您犯的一个错误,“百分比 CPU”的名称是虚拟机规模集,您需要将其更改为“ CpuPercentage ”,它是您想要的应用服务计划。有关详细信息,请参阅metric_name

于 2019-11-05T09:20:55.650 回答