skip to Main Content

I’m trying to deploy a dashboard that displays a couple of metrics for a Service Bus Queue in the Azure Portal using Bicep. Creating the tiles itself works fine, but I’m struggling with displaying the metrics for a filtered resource. Currently, my Bicep file looks like this:

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

The chart is created but displays the metrics for the entire Service Bus instead of the specific Queue. How can I add the filter to the Bicep so that only the metrics for a specific Service Bus Queue are displayed?

2

Answers


  1. Deploy filtered metrics on Azure dashboard with Bicep

    It seems you’re missing on providing the correct resource ID in place of namespace. As per your bicep configuration should include the queue’s path within the Service Bus namespace.

    Bicep configuration:

    param location string
    param dashboardName string
    param tags object
    param serviceBusNamespaceId string
    param serviceBusQueueName string
    param chartTitle string
    
    
    var serviceBusQueueResourceId = '${serviceBusNamespaceId}/queues/${serviceBusQueueName}'
    
    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: serviceBusQueueResourceId
                              }
                              name: 'ActiveMessages'
                              aggregationType: 0
                              namespace: 'Microsoft.ServiceBus/namespaces'
                              metricVisualization: {
                                displayName: 'Active Messages'
                              }
                            }
                            {
                              resourceMetadata: {
                                id: serviceBusQueueResourceId
                              }
                              name: 'DeadLetteredMessages'
                              aggregationType: 0
                              namespace: 'Microsoft.ServiceBus/namespaces'
                              metricVisualization: {
                                displayName: 'Dead-Lettered Messages'
                              }
                            }
                            {
                              resourceMetadata: {
                                id: serviceBusQueueResourceId
                              }
                              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'
                  }
                }
              }
            }
          }
        }
      }
    }
    

    Deployment Succeeded:

    enter image description here

    enter image description here

    This configuration will display the metrics of the specific Service Bus Queue by mentioning the resourceId of the queue. This makes sure that the metrics showed were specific to the queue rather than the entire Service Bus namespace.

    Reference:

    https://learn.microsoft.com/en-us/azure/azure-portal/azure-portal-dashboards

    https://learn.microsoft.com/en-us/azure/service-bus-messaging/monitor-service-bus-reference

    Login or Signup to reply.
  2. Just created a dashboard and checked the configuration using az portal dashboard cli command (see documentation).

    The filters property needs to be inside a filterCollection property and you need to specify the servicebus namespace resource id rather than the name

    resource servicebus 'Microsoft.ServiceBus/namespaces@2022-10-01-preview' existing = {
      name:serviceBusNamespace
      // Scope may need to be adjusted if servicebus is not int he same subscription / resource group
      // scope: resourceGroup(serviceBusRGName)
    }
    
    resource dashboard 'Microsoft.Portal/dashboards@2020-09-01-preview' = {
      name: dashboardName
      location: location
      properties: {
        lenses: [
          {
            order: 0
            parts: [
              {
                metadata: {
                  settings: {
                    content: {
                      options: {
                        chart: {
                          filterCollection: {
                            filters: [
                              {
                                property: 'EntityName'
                                operator: 'Equals'
                                values: [
                                  serviceBusQueueName
                                ]
                              }
                            ]
                          }                      
                          metrics: [
                            {
                              resourceMetadata: {
                                id: servicebus.id // need the resource id here
                              }
                              name: 'activeMessages'
                              aggregationType: 0
                              namespace: 'Microsoft.ServiceBus/namespaces'
                              metricVisualization: {
                                displayName: 'Active Messages'
                              }
                            }
                            ...
                          ]
                          ...
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
        ...
      }
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search