1

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?

Update

Using the az portal dashboard cli command gives you a much more complete ARM template of your dashboard then simply downloading the template from the Azure Portal (thanks Thomas!). Because of this I found out that we need to define filters in the metadata as well as a filterCollection in the chart and that 'property' needs to be 'key' in the filterCollection. Here's the working 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'
              }
            }
          }
        }
      }
    }
  }
}

2 Answers 2

2

Just created a dashboard from azure portal and checked the configuration using az portal dashboard cli command (see documentation):

  • The filters property needs to be inside a filterCollection property
  • 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'
                          }
                        }
                        ...
                      ]
                      ...
                    }
                  }
                }
              }
            }
          }
        ]
      }
    ]
    ...
  }
}

Sign up to request clarification or add additional context in comments.

2 Comments

Your az portal dashboard tip helped me solve this! It turns out that the solution is a combination of yours and Vinay B's answer. You need to define a filters object in the metadata as well as the filterCollection in the chart. And 'property' in the filters array needs to be changed to 'key'. I've updated my post to reflect the complete solution and I'll mark your answer as correct because the az portal dashboard tip sent me down the correct path :).
Good to hear you sorted out :-)
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

3 Comments

Hi Vinay, thanks for taking the time to look into this. I've tried this before (and have tried it again, just to be sure ;) ), but this gives me an error in the graph: "Error retrieving data." I think the problem with this is that the metrics I'm trying to display aren't natively (for lack of a better word) available on a Queue, they're metrics for a Service Bus. However, when manually creating the dashboard I am able to filter per Queue, so it must be possible to do this through (something like) Bicep.
dimensions: [ { name: 'EntityName' value: serviceBusQueueName } ] Apply this for each metric in your dashboard definition and try again @StuartvdLee
I've applied your suggestion in the same way as I had defined filters in my original Bicep, but naming it dimensions instead and declaring it on every metric. Sadly, I still get the metrics for the entire Service Bus as opposed to a specific Service Bus Queue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.