Azure部署:首次部署时不支持的指标

3gtaxfhh  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(104)

我们正面临一个恼人的问题,即在新环境的第一次部署尝试中出现错误:

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

如果我们重新部署一切正常。应根据文档支持指标“CpuPercentage”:https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftwebserverfarms
我们的二头肌代码:

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'
            }
          }
        ]
      }
    ]    
  }
}

关于可能导致此问题的原因或是否有任何解决方法,有任何想法吗?试图分裂成单独的模块,以引入一点延迟,但这似乎也不起作用。

yvfmudvl

yvfmudvl1#

Azure部署:首次部署时不支持的度量:
通常,当代码中给出的指标不受特定Azure资源支持时,会出现不支持的指标错误。
但是应该支持"CpuPercentage",因为它也在MS Doc中明确给出。度量可能需要更多的时间才能变得可用于新添加的资源。
在这种情况下,频繁地重新部署部署可以解决问题,因为到那时度量将可用。
虽然重新部署可以快速解决问题,但还有另一种方法可以解决这个问题。您可以在现有代码中添加部署脚本,方法是添加一个带有部署时间段的超时标志。使用deployment script templates并根据您的环境更改timeout标志值。

resource  awaitscript  'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: ''
location: location
kind: 'AzurePowerShell'
properties: {
azPowerShellVersion: '9.7'
scriptContent: '''
timeout: 'PT40M'
retentionInterval: ''
'''
}
}

添加上面的代码后,添加一个dependsOn块来指出await脚本&一个应用服务计划,如图所示。

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-lalluapp'
....code...
dependsOn: [
    appServicePlan,
    awaitscript
  ]
}
  • 我在我的环境中尝试了与您相同的代码,但没有添加任何部署脚本,它在第一次部署中对我有效。*

main.bicep

param webAppName string = ''
param location string = resourceGroup().location 
var appServiceplanname = ''

resource appServicePlan 'Microsoft.Web/serverfarms@2020-06-01' = {
  name: appServiceplanname
  location: location
  properties: {
    reserved: true
  }
  sku: {
    name: sku
  }
  kind: 'linux'
}

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-lalluapp'
  location: location
  //tags: ''
  properties: {
    targetResourceLocation: location
    targetResourceUri: appServicePlan.id
    enabled: true
    name: 'autoscale-lalluapp'
    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'
            }
          }
        ]
      }
    ]
  }
}

main.parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"value": "xxxxxapp"
},
"sku": {
"value": "F1"
},
"linuxFxVersion": {
"value": "xxxx"
     }
   }
}

部署成功:

有关问题,请参阅MS github

相关问题