如何在Bicep创建指标警报时避免‘找不到storage_percent指标’错误?
问题:Azure SQL数据库与Metric Alert同时部署失败
我有一段Bicep代码,用于创建Azure SQL Database和磁盘空间使用率达80%时触发的Metric Alert。当数据库已存在时,部署可以正常运行;但同时创建数据库和警报时,部署会失败,报错Couldn't find a metric named storage_percent。流水线针对空资源组运行时,首次部署必败,但自动重试可成功——这无法接受,因为这段代码属于一个耗时约10分钟的大型部署的一部分。
Bicep代码
resource sqlServer 'Microsoft.Sql/servers@2021-02-01-preview' existing = { name: sqlServerName resource sqlDatabase 'databases' = { name: sqlDatabaseName properties: { // ... } // ... } } resource diskSpaceAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = { name: '${sqlServer::sqlDatabase.name} Disk Space Low' location: 'global' properties: { description: '${sqlServer::sqlDatabase.name} database disk usage is above 80%' criteria: { 'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria' allOf: [ { name: 'StoragePercentGt80' metricName: 'storage_percent' threshold: 80 operator: 'GreaterThan' timeAggregation: 'Maximum' criterionType: 'StaticThresholdCriterion' skipMetricValidation: true // 尝试解决问题时添加的配置 } ] } enabled: true evaluationFrequency: 'PT1H' scopes: [ sqlServer::sqlDatabase.id ] severity: 2 windowSize: 'PT1H' actions: [ { actionGroupId: errorAlertingActionGroupId } ] } }
原始错误信息
{ "code": "DeploymentFailed", "target": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Resources/deployments/...", "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.", "details": [ { "code": "BadRequest", "target": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Resources/deployments/...", "message": "Couldn't find a metric named storage_percent. Make sure the name is correct. Activity ID: ..." } ] }
补充信息
- 曾尝试添加
skipMetricValidation: true参数,未解决问题 - 部署区域:英国南部(UK South)
- 网络配置:
- SQL Server禁用公网访问,配置了专用终结点连接
- Log Analytics工作区拥有Azure Monitor专用链接范围(不确定Metric Alerts是否依赖此资源)
内容的提问来源于stack exchange,提问作者Mike
相关产品推荐
相关产品推荐

