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

如何通过Bicep在Azure仪表板部署带过滤的Service Bus队列指标

问题

尝试使用Bicep在Azure门户部署仪表板,用于展示Service Bus队列的多项指标。磁贴创建正常,但无法展示指定队列的过滤后指标——当前图表显示的是整个Service Bus命名空间的指标,而非目标队列。原Bicep代码如下:

resource dashboard 'Microsoft.Portal/dashboards@2020-09-01-preview' = {
  name: dashboardName
  location: location
  tags: tags
  properties: {
    lenses: [
      {
        order: 0
        parts: [
          {
            position: {
              x: 0
              y: 1
              rowSpan: 3
              colSpan: 5
            }
            metadata: {
              inputs: [
                {
                  name: 'options'
                  isOptional: true
                }
                {
                  name: 'sharedTimeRange'
                  isOptional: true
                }
              ]
              type: 'Extension/HubsExtension/PartType/MonitorChartPart'
              settings: {
                content: {
                  options: {
                    chart: {
                      filters: [
                        {
                          property: 'EntityName'
                          operator: 'Equals'
                          values: [
                            serviceBusQueueName
                          ]
                        }
                      ]
                      metrics: [
                        {
                          resourceMetadata: {
                            id: serviceBusNamespace
                          }
                          name: 'activeMessages'
                          aggregationType: 0
                          namespace: 'Microsoft.ServiceBus/namespaces'
                          metricVisualization: {
                            displayName: 'Active Messages'
                          }
                        }
                        {
                          resourceMetadata: {
                            id: serviceBusNamespace
                          }
                          name: 'deadLetteredMessages'
                          aggregationType: 0
                          namespace: 'Microsoft.ServiceBus/namespaces'
                          metricVisualization: {
                            displayName: 'Dead-Lettered Messages'
                          }
                        }
                        {
                          resourceMetadata: {
                            id: serviceBusNamespace
                          }
                          name: 'completeMessage'
                          aggregationType: 0
                          namespace: 'Microsoft.ServiceBus/namespaces'
                          metricVisualization: {
                            displayName: 'Completed Messages'
                          }
                        }
                      ]
                      title: chartTitle
                      titleKind: 2
                      visualization: {
                        chartType: 2
                        legendVisualization: {
                          isVisible: true
                          position: 2
                          hideSubtitle: false
                        }
                        axisVisualization: {
                          x: {
                            isVisible: true
                            axisType: 2
                          }
                          y: {
                            isVisible: true
                            axisType: 1
                          }
                        }
                        disablePinning: true
                      }
                    }
                  }
                }
              }
            }
          }
        ]
      }
    ]
    metadata: {
      model: {
        timeRange: {
          value: {
            relative: {
              duration: 24
              timeUnit: 1
            }
          }
          type: 'MsPortalFx.Composition.Configuration.ValueTypes.TimeRange'
        }
        filterLocale: {
          value: 'en-us'
        }
        filters: {
          value: {
            MsPortalFx_TimeRange: {
              model: {
                format: 'local'
                granularity: 'auto'
                relative: '24h'
              }
              displayCache: {
                name: 'Local Time'
                value: 'Past 24 hours'
              }
            }
          }
        }
      }
    }
  }
}
解决方案

使用az portal dashboard CLI命令可获取比Azure门户直接下载更完整的ARM模板,由此确定需要做两处修改:

  • 在磁贴的metadata下新增filters节点,定义队列名称过滤规则
  • 将图表filters中的property字段改为key

修正后的Bicep代码如下:

resource dashboard 'Microsoft.Portal/dashboards@2020-09-01-preview' = {
  name: dashboardName
  location: location
  tags: tags
  properties: {
    lenses: [
      {
        order: 0
        parts: [
          {
            position: {
              x: 0
              y: 1
              rowSpan: 3
              colSpan: 5
            }
            metadata: {
              inputs: [
                {
                  name: 'options'
                  isOptional: true
                }
                {
                  name: 'sharedTimeRange'
                  isOptional: true
                }
              ]
              filters: {
                EntityName: {
                  model: {
                    operator: 'equals'
                    values: [
                      'queue-dr-filestorage-xbrlfeitenprocessed-${environment}'
                    ]
                  }
                }
              }
              type: 'Extension/HubsExtension/PartType/MonitorChartPart'
              settings: {
                content: {
                  options: {
                    chart: {
                      filters: [
                        {
                          key: 'EntityName'
                          operator: 'Equals'
                          values: [
                            serviceBusQueueName
                          ]
                        }
                      ]
                      metrics: [
                        {
                          resourceMetadata: {
                            id: serviceBusNamespace
                          }
                          name: 'activeMessages'
                          aggregationType: 0
                          namespace: 'Microsoft.ServiceBus/namespaces'
                          metricVisualization: {
                            displayName: 'Active Messages'
                          }
                        }
                        {
                          resourceMetadata: {
                            id: serviceBusNamespace
                          }
                          name: 'deadLetteredMessages'
                          aggregationType: 0
                          namespace: 'Microsoft.ServiceBus/namespaces'
                          metricVisualization: {
                            displayName: 'Dead-Lettered Messages'
                          }
                        }
                        {
                          resourceMetadata: {
                            id: serviceBusNamespace
                          }
                          name: 'completeMessage'
                          aggregationType: 0
                          namespace: 'Microsoft.ServiceBus/namespaces'
                          metricVisualization: {
                            displayName: 'Completed Messages'
                          }
                        }
                      ]
                      title: chartTitle
                      titleKind: 2
                      visualization: {
                        chartType: 2
                        legendVisualization: {
                          isVisible: true
                          position: 2
                          hideSubtitle: false
                        }
                        axisVisualization: {
                          x: {
                            isVisible: true
                            axisType: 2
                          }
                          y: {
                            isVisible: true
                            axisType: 1
                          }
                        }
                        disablePinning: true
                      }
                    }
                  }
                }
              }
            }
          }
        ]
      }
    ]
    metadata: {
      model: {
        timeRange: {
          value: {
            relative: {
              duration: 24
              timeUnit: 1
            }
          }
          type: 'MsPortalFx.Composition.Configuration.ValueTypes.TimeRange'
        }
        filterLocale: {
          value: 'en-us'
        }
        filters: {
          value: {
            MsPortalFx_TimeRange: {
              model: {
                format: 'local'
                granularity: 'auto'
                relative: '24h'
              }
              displayCache: {
                name: 'Local Time'
                value: 'Past 24 hours'
              }
            }
          }
        }
      }
    }
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 17:53:16