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

如何为Azure Monitor静态阈值警报实现failingPeriods功能?

问题:Azure Monitor静态阈值警报如何实现类似failingPeriods的功能?

我尝试为Azure Monitor静态阈值警报添加failingPeriods配置(期望实现如多指标规则中那样,在指定数量的评估周期内满足一定失败次数才触发警报),但发现静态阈值规则不支持该配置。请问是否有替代方案可实现此功能?

示例Bicep代码(包含无效的failingPeriods配置):

resource alert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
  name: 'testalert'
  location: 'location'
  properties: {
    description: 'testalert'
    severity: 3
    enabled: true
    scopes: [
      // 目标资源ID
    ]
    evaluationFrequency: 'PT5M'
    windowSize: 'PT5M'
    criteria: {
      allOf: [
        {
          threshold: 0
          name: 'DeadLetteredCount'
          metricNamespace: 'microsoft.eventgrid/topics'
          metricName: 'DeadLetteredCount'
          operator: 'greaterthan'
          timeAggregation: 'count'
          criterionType: 'StaticThresholdCriterion'
          failingPeriods: {
            numberOfEvaluationPeriods: 3
            minFailingPeriodsToAlert: 2
          }
        }
      ]
      'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
    }
    autoMitigate: false
    targetResourceType: 'Microsoft.EventGrid/topics'
    targetResourceRegion: location
    actions: [
      {
        actionGroupId: actionGroupId
      }
    ]
  }
}

替代方案

静态阈值规则确实不支持failingPeriods参数,要实现类似“连续/指定数量周期内触发才警报”的逻辑,可采用以下两种方案:

1. 切换到动态阈值规则(DynamicThresholdCriterion)

动态阈值规则原生支持failingPeriods配置,可直接实现你需要的多周期评估逻辑。修改后的Bicep代码示例:

resource alert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
  name: 'testalert'
  location: 'location'
  properties: {
    description: 'testalert'
    severity: 3
    enabled: true
    scopes: [
      // 目标资源ID
    ]
    evaluationFrequency: 'PT5M'
    windowSize: 'PT5M'
    criteria: {
      allOf: [
        {
          name: 'DeadLetteredCount'
          metricNamespace: 'microsoft.eventgrid/topics'
          metricName: 'DeadLetteredCount'
          operator: 'GreaterThan'
          timeAggregation: 'Count'
          criterionType: 'DynamicThresholdCriterion'
          // 配置动态阈值参数,可根据实际需求调整
          dynamicThresholdConfiguration: {
            sensitivity: 'Medium'
            failingPeriods: {
              numberOfEvaluationPeriods: 3
              minFailingPeriodsToAlert: 2
            }
          }
        }
      ]
      'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
    }
    autoMitigate: false
    targetResourceType: 'Microsoft.EventGrid/topics'
    targetResourceRegion: location
    actions: [
      {
        actionGroupId: actionGroupId
      }
    ]
  }
}

2. 调整窗口大小与评估频率,配合聚合逻辑

如果必须使用静态阈值,可通过扩大windowSize并调整时间聚合方式,间接实现类似效果:

  • 将windowSize设置为覆盖目标数量的评估周期(例如PT15M对应3个5分钟周期),保持evaluationFrequency不变
  • 时间聚合使用Total或Average,同时调整阈值以匹配整个窗口的累计/平均触发条件
  • 这种方式相当于在每个评估周期检查过去N个周期的聚合结果,达到类似“N个周期内满足条件即警报”的效果

修改后的静态阈值示例:

resource alert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
  name: 'testalert'
  location: 'location'
  properties: {
    description: 'testalert'
    severity: 3
    enabled: true
    scopes: [
      // 目标资源ID
    ]
    evaluationFrequency: 'PT5M'
    windowSize: 'PT15M' // 覆盖3个评估周期
    criteria: {
      allOf: [
        {
          threshold: 2 // 调整为3个周期内累计达到2次触发的阈值
          name: 'DeadLetteredCount'
          metricNamespace: 'microsoft.eventgrid/topics'
          metricName: 'DeadLetteredCount'
          operator: 'greaterthan'
          timeAggregation: 'Total' // 累计聚合
          criterionType: 'StaticThresholdCriterion'
        }
      ]
      'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
    }
    autoMitigate: false
    targetResourceType: 'Microsoft.EventGrid/topics'
    targetResourceRegion: location
    actions: [
      {
        actionGroupId: actionGroupId
      }
    ]
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 06:15:10