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

如何使用Azure CLI创建基于failedLocationCount的Webtest指标告警

Azure CLI 创建Webtest失败探测位置数告警的正确方法

错误原因

基于Webtest失败探测位置数的告警属于专用的位置可用性告警规则类型,无法通过普通指标告警的--condition参数直接指定指标名创建。该类告警使用Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria专用规则结构,通用的az monitor metrics alert create命令不支持直接传入该结构参数,因此会报指标不存在的错误。

解决方法

通过az resource create直接创建告警规则资源,手动指定专用规则结构即可,具体操作如下:

前置准备

提前获取以下资源的ID:

  • 目标Application Insights资源ID
  • 对应Webtest的资源ID
  • 触发告警时调用的动作组ID

示例代码(PowerShell环境)

# 自定义参数配置
$alertName = "myAlertName"
$rgName = "myRgName"
$aiId = "<替换为Application Insights资源ID>"
$webTestId = "<替换为对应Webtest资源ID>"
$actionGroupId = "<替换为动作组资源ID>"
$failedLocationThreshold = 1
$alertSeverity = 1

# 创建告警规则
az resource create `
  --resource-type Microsoft.Insights/metricAlerts `
  --name $alertName `
  --resource-group $rgName `
  --api-version 2018-03-01 `
  --properties "{
    'description': 'Webtest失败探测位置数阈值告警',
    'severity': $alertSeverity,
    'enabled': true,
    'scopes': ['$aiId'],
    'evaluationFrequency': 'PT1M',
    'windowSize': 'PT5M',
    'criteria': {
      'odata.type': 'Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria',
      'webTestId': '$webTestId',
      'componentId': '$aiId',
      'failedLocationCount': $failedLocationThreshold
    },
    'actions': [
      {
        'actionGroupId': '$actionGroupId'
      }
    ],
    'autoMitigate': true
  }"

注意事项

  • 若使用Bash环境运行,将命令中的换行符`替换为\,并调整外层引号为双引号即可
  • evaluationFrequency为告警评估频率,windowSize为评估时间窗口,上述示例为每分钟评估最近5分钟的探测数据,可根据需求自行调整
  • 所有尖括号包裹的参数需要替换为你实际环境中的资源ID

内容的提问来源于stack exchange,提问作者Daniel W.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 14:45:02