Skip to main content
Local time for programmatically created Azure Dashboards
  1. Posts/

Local time for programmatically created Azure Dashboards

·428 words·3 mins
Christoph Petersen
Author
Christoph Petersen

When you begin to operationalize your deployments and want to add monitoring one of the things you might do is to create shared dashboards as part of your deployment. A shared dashboard is basically the same as a non-shared dashboard except it is a full Azure resource, lives in a resource group and can be created through ARM.

Dashboards help to quickly nail down on issues with operations when incident response get triggered by an outside event like an alert or through continuous monitoring. What is really helpful is to have the widgets display metrics in the local timezone so that putting things into temporal context is easy.

If you create a shared dashboard through ARM without specifying metadata the time will be displayed in UTC. The following resource adds a single metrics widget for the memory utilization for an App Service Plan to demonstrate the logic:

{
  "type": "Microsoft.Portal/dashboards",
  "name": "[variables('nameDashboard')]",
  "apiVersion": "2015-08-01-preview",
  "location": "[variables('locationDashboard')]",
  "tags": {
    "hidden-title": "[variables('nameDashboard')]"
  },
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverFarms', variables('nameFarm'))]"
  ],
  "properties": {
    "lenses": {
      "0": {
        "order": 0,
        "parts": {
          "0": {
            "position": {
              "x": 0,
              "y": 0,
              "colSpan": 4,
              "rowSpan": 5
            },
            "metadata": {
              "inputs": [
                {
                  "name": "options",
                  "isOptional": true
                },
                {
                  "name": "sharedTimeRange",
                  "isOptional": true
                }
              ],
              "type": "Extension/HubsExtension/PartType/MonitorChartPart",
              "settings": {
                "content": {
                  "options": {
                    "chart": {
                      "metrics": [
                        {
                          "resourceMetadata": {
                            "id": "[resourceId('Microsoft.Web/serverFarms', variables('nameFarm'))]"
                          },
                          "name": "MemoryPercentage",
                          "aggregationType": 4,
                          "namespace": "Microsoft.Web/serverFarms",
                          "metricVisualization": {
                            "displayName": "Memory Percentage"
                          }
                        }
                      ],
                      "title": "App Service Plan",
                      "visualization": {
                        "chartType": 2,
                        "legendVisualization": {
                          "isVisible": true,
                          "position": 2,
                          "hideSubtitle": false
                        },
                        "axisVisualization": {
                          "x": {
                            "isVisible": true,
                            "axisType": 2
                          },
                          "y": {
                            "isVisible": true,
                            "axisType": 1
                          }
                        }
                      },
                      "filterCollection": {
                        "filters": []
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Notice that the default time filter is set to the last 24 hours in UTC:

Default time filter for ARM created dashboards

You can change the time span and the adjustment to local time by specifying metadata for the dashboard resource in your ARM template:

{
  "type": "Microsoft.Portal/dashboards",
  "name": "[variables('nameDashboard')]",
  "apiVersion": "2015-08-01-preview",
  "location": "[variables('locationDashboard')]",
  "tags": {
    "hidden-title": "[variables('nameDashboard')]"
  },
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverFarms', variables('nameFarm'))]"
  ],
  "properties": {
    "lenses": {
      // removed for brevity
    },
    "metadata": {
      "model": {
        "filters": {
          "value": {
            "MsPortalFx_TimeRange": {
              "model": {
                "format": "local",
                "granularity": "auto",
                "relative": "3d"
              },
              "displayCache": {
                "name": "Local Time",
                "value": "Past 3 days"
              }
            }
          }
        }
      }
    }
  }
}

When you add metadata to the dashboard definition like in the example above. You can define the time span that should be displayed in the dashboard in addition to enable adjusting the time to local time.

Explicit set time filter with adjustment to local time

Related

Setting App Service connection strings in ARM

·144 words·1 min
For automatic deployment of test environments we are spinning up App Service instances and want to automatically set connection strings for the database and other services in the same template.

Inventory VMs with PowerShell DSC and Log Analytics

·501 words·3 mins
Photo by Matt Artz on Unsplash In many scenarios there is the requirement to enrich or lookup data with meta information from the infrastructure. In this scenario a file with machine, location and other meta information was placed during deployment on the VM for both Azure and AWS.

Azure Notification Hub race condition

·375 words·2 mins
Both development and production environments are deployed in a fully automated fashion using ARM templates. As part of these deployments we also create Notification Hubs and related authorization rules.