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

Azure首次部署遇UnsupportedMetric错误(CpuPercentage)求排查方案

问题:App Service Plan首次部署自动缩放时触发UnsupportedMetric错误

我们在全新环境首次部署时遇到以下错误,重新部署后恢复正常。根据官方文档,CpuPercentage指标是Microsoft.Web/serverfarms支持的指标。

错误信息

resource: /subscriptions/XX/resourceGroups/rg-YY/providers/Microsoft.Web/serverfarms/plan-ZZ, 
metricnamespace: microsoft.web/serverfarms, metricname: CpuPercentage (Code: UnsupportedMetric)

部署用Bicep代码

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appName
  location: location
  kind: 'windows'
  properties: {
    reserved: false
    maximumElasticWorkerCount: 10
  }
  sku: {
    tier: tier
    name: skuName
  }
  tags: tags
}


resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-${appName}'
  location: location
  tags: tags
  properties: {
    targetResourceLocation: location
    targetResourceUri: appServicePlan.id
    enabled: true
    name: 'autoscale-${appName}'
    profiles: [
      {
        capacity: {
          default: '1'
          maximum: '3'
          minimum: '1'
        }
        name: 'DefaultAutoscaleProfile'
        rules: [
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'GreaterThan'
              threshold: 70
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Increase'
              type: 'ChangeCount'
              value: '1'
            }
          }
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'LessThan'
              threshold: 45
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Decrease'
              type: 'ChangeCount'
              value: '1'
            }
          }
        ]
      }
    ]    
  }
}

可能原因

  • 资源元数据同步延迟:首次创建App Service Plan后,Azure Monitor的指标目录未完成该资源的元数据同步,导致自动缩放规则部署时无法识别CpuPercentage指标。这种延迟是Azure内部注册/同步机制导致,与资源本身的就绪状态无关。
  • ARM部署时序问题:虽然Bicep通过appServicePlan.id建立了依赖关系,但Azure资源提供者之间的内部状态同步可能滞后于ARM部署的完成信号,自动缩放规则部署时,目标App Service Plan的指标尚未在Monitor系统中注册。

可行解决办法

  • 添加部署等待逻辑:在部署自动缩放规则前,加入2-5分钟的等待时间,确保指标元数据完成同步。可通过CI/CD流程的等待步骤或Azure CLI脚本(如sleep 300)实现。
  • 拆分资源部署:将App Service Plan与自动缩放规则分开展开部署,先完成App Service Plan的部署并确认资源就绪后,再部署自动缩放设置,避免一次性部署所有资源。
  • 延迟启用自动缩放:在自动缩放设置中先将enabled设为false,部署完成后再手动或通过脚本改为true,绕过部署时的指标校验。
  • 升级API版本:尝试将自动缩放规则的API版本升级至较新版本(如2023-05-01-preview),新版本可能优化了资源依赖的处理逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 22:53:14