LLI Wiki — My Digital Knowledge Base

Grafana dashboards for Azure SQL and Azure Batch

Designing a wallboard, choosing the Azure Monitor data source and Log Analytics workspace, and keeping dashboards as JSON in Git.

A modern DBA no longer just runs queries by hand: you want the state of the whole fleet at a glance, on a wall screen, and the same state tracked in Git. This is how I build Grafana dashboards for Azure SQL (elastic pools, databases) and Azure Batch (tasks, jobs), and the rules that save me from a day lost on a "No data" panel.

Architecture

Azure metrics and logs flow into a Log Analytics workspace through diagnostic settings. Grafana reads them with the Azure Monitor data source in "Logs" mode, and dashboards are exported as JSON into Git.

flowchart LR
    A["Azure SQL : pools and databases"] --> C["Diagnostic settings"]
    B["Azure Batch : tasks and jobs"] --> C
    C --> D["Log Analytics (workspaces)"]
    D --> E["Grafana : Azure Monitor source"]
    E --> F["Wallboard (wall screen)"]
    E --> G["Detail dashboards"]
    G --> H["JSON export"]
    H --> I["Git repository"]

Pick the right data source + workspace pair

Pitfall number one: a perfectly valid query returns zero rows when the data source or the workspace does not match the monitored domain. In my setup SQL metrics and Batch logs live in different workspaces, hence different Azure Monitor data sources. My rule: for a new panel I copy the datasource.uid and the azureLogAnalytics.resources list from a dashboard that already works in the same domain instead of guessing them.

Designing a wallboard

A wallboard is read from three metres away, not from 50 cm.

For fleets of thousands of databases, a state-timeline or heatmap with one row per database is unusable: each row is a fraction of a pixel. I pivot time into fixed columns (the 24 hours of the day) and show a coloured table instead: it scrolls, so row count stops being a rendering budget. I write the 24 columns explicitly with maxif rather than evaluate pivot(), because pivot() does not create the column of an empty bucket and shifts the field overrides.

AzureMetrics
| where $__timeFilter(TimeGenerated)
| where ResourceProvider == "MICROSOFT.SQL" and MetricName == "cpu_percent"
| where ResourceId contains "/ELASTICPOOLS/"
| summarize CpuMax = max(Maximum) by bin(TimeGenerated, $__interval), Pool = Resource
| order by TimeGenerated asc

The final order by TimeGenerated asc is not cosmetic: without a monotonic time column the data source returns a "long" frame the panel cannot draw.

For Batch the same logic applies: count tasks by result and job from the service log. Column names depend on the enabled categories, so I guard them with column_ifexists and check in my workspace.

AzureDiagnostics
| where $__timeFilter(TimeGenerated)
| where ResourceProvider == "MICROSOFT.BATCH"
| extend Job = tostring(column_ifexists("jobId_s", "")), Result = tostring(column_ifexists("executionInfo_result_s", ""))
| summarize Success = countif(Result == "Success"), Failed = countif(Result == "Failure") by Job

Conventions for dashboards kept as JSON in Git

Rule Why
File named <slug>__<uid>.json, one folder per Grafana folder find a dashboard without opening it
Export with GET /api/dashboards/uid/<uid>, keep the dashboard object stable format, readable diff
One .kql file per panel or dashboard next to it the query can be read and reviewed without escaped JSON
All visible text in English (titles, legends, column names) one language for the whole team
No secrets: service-account tokens stay out of the repo the JSON holds data source UIDs, never secrets
Meaningful commit message on every update Grafana history and Git tell the same story

The flow: change it in Grafana, export, update the .kql, commit both.

Lessons learned

Mastodon LLIMastodon SocialFosstodon