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.
- Few panels, big, one question each ("which pool is above 80% CPU?").
- Consistent threshold colours everywhere: green, orange, red, and the same colours for Success / Failed / ScheduleFail.
- Tables sorted by severity rather than charts that cannot be read from a distance; auto refresh; time picker hidden when no panel uses it.
- A separate "detail" dashboard: the wall shows the anomaly, the detail explains it.
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
$__timeIntervaldoes not exist for Azure Logs: use$__interval, otherwise Kusto answers 400.- Multi-value variables: Grafana injects them as a glob
{value}, even with a single selection.== "$var"returns nothing; usein (${var:singlequote}). The panel shows "No data" with no error at all. allValuemust carry its own quotes ("'__all__'"), because:singlequoteis not applied to it.- Calendar-period panels (30 days, month): the time picker still caps the query when
dashboardTimeis true. Set it tofalse. - Never strip the hash suffix from job ids to make labels prettier: you merge distinct jobs.
- Verify without screenshots: when the image renderer is not installed, replay each query through
POST /api/ds/queryand inspect the frame shape.