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?
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'
}
}
}
}
}
}
}
}
Just created a dashboard from azure portal and checked the configuration using az portal dashboard
cli command (see documentation):
filters
property needs to be inside a filterCollection
propertyresource 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'
}
}
...
]
...
}
}
}
}
}
}
]
}
]
...
}
}