You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Terraform配置多条件监控告警新增条件遇维度限制错误

错误原因

Azure平台对多条件指标告警有强制限制:单条告警规则包含多个criteria监控条件时,每个条件内的所有维度的values字段只能传入1个明确的具体值,不允许使用通配符*,也不允许传入多个值。你当前配置中两个criteria的ApiName维度都用了通配符["*"],不符合平台限制所以触发报错。

解决方案

你可以根据实际业务需求选以下任意一种方案调整:

方案1:拆分多个独立告警规则(适用需要用通配符匹配所有维度的场景)

如果你的监控逻辑需要用*匹配所有ApiName,不能指定单个具体维度值,就不要把多个条件放到同一条告警规则里,拆成多个独立的azurerm_monitor_metric_alert资源即可,单条件的告警规则没有维度取值数量限制。
示例配置:

# 第一条告警规则,对应原第一个监控条件
resource "azurerm_monitor_metric_alert" "example_1" {
  name                = "example-metricalert-1"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
    }
  }

  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}

# 第二条告警规则,对应原第二个监控条件
resource "azurerm_monitor_metric_alert" "example_2" {
  name                = "example-metricalert-2"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
    }
  }

  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}

方案2:修改维度为单个具体值(适用需要单条告警多条件联动的场景)

如果你的业务逻辑要求多个条件同时/任意满足才触发告警,必须放在同一条告警规则里,就需要把每个criteria下的维度取值改成单个具体值,不能用通配符。同时可以通过criteria_operator参数指定多条件的逻辑关系,可选值为AllOf(全部满足触发)、AnyOf(任意满足触发)。
示例配置:

resource "azurerm_monitor_metric_alert" "example" {
  name                = "example-metricalert"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50 for both GetBlob and PutBlob."
  criteria_operator   = "AllOf" # 按需调整为AnyOf

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["GetBlob"] # 替换为你要监控的具体Api名称,仅允许1个值
    }
  }

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["PutBlob"] # 替换为你要监控的具体Api名称,仅允许1个值
    }
  }

  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}
额外优化建议

如果你两个监控条件的指标、聚合方式、阈值都完全一致,只是监控的维度值不同,不需要拆分多条件,直接在单个criteria的dimension.values里传入所有要监控的Api名称即可,单条件告警支持传入多个维度值,也支持通配符,配置更简洁:

dimension {
  name     = "ApiName"
  operator = "Include"
  values   = ["GetBlob", "PutBlob", "DeleteBlob"] # 可传入多个值,也可用*
}

内容的提问来源于stack exchange,提问作者Mr_Unchained

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 01:24:08