Grafana’s Azure Monitor data source doesn’t just show you metrics; it lets you query Azure’s underlying metrics store using a powerful, SQL-like language.
Let’s get this set up. We’ll need a few things from Azure first:
-
Azure AD Application Registration: This is how Grafana will authenticate to Azure.
- Go to the Azure portal.
- Search for "Azure Active Directory".
- Under "Manage", select "App registrations".
- Click "+ New registration".
- Give it a name, e.g.,
grafana-azure-monitor-ds. - Under "Supported account types", choose "Accounts in this organizational directory only (Default Directory only)".
- Leave "Redirect URI" blank for now.
- Click "Register".
- Note down the "Application (client) ID" and "Directory (tenant) ID". You’ll need these.
- Under "Manage", select "Certificates & secrets".
- Click "+ New client secret".
- Add a description, e.g.,
grafana-key. - Set an expiry, e.g., "6 months".
- Click "Add".
- Immediately copy the "Value" of the client secret. This is your password. It won’t be shown again.
-
Azure Role Assignment: The application needs permission to read metrics.
- Go to the Azure portal.
- Navigate to the Azure subscription you want Grafana to monitor.
- Under "Access control (IAM)", click "+ Add" -> "Add role assignment".
- For "Role", select
Monitoring Reader. This role has read-only access to most monitoring data. - For "Assign access to", select "User, group, or service principal".
- Under "Members", click "+ Select members".
- Search for the name of the App registration you created (e.g.,
grafana-azure-monitor-ds). - Select it and click "Add".
- Click "Review + assign".
Now, back in Grafana:
-
Add Data Source:
- Log in to your Grafana instance.
- Go to "Configuration" (gear icon) -> "Data sources".
- Click "Add data source".
- Search for "Azure Monitor" and select it.
-
Configure Data Source:
- Name:
Azure Monitor(or whatever you prefer). - Azure Cloud: Select your Azure environment (e.g.,
Azure Public). - Authentication Method:
Service Principal. - Tenant ID: Paste your Azure AD Directory (tenant) ID.
- Client ID: Paste your Azure AD Application (client) ID.
- Client Secret: Paste the value of the client secret you copied.
- Subscription ID: Paste your Azure Subscription ID.
- Azure Monitor API: Leave as
Azure Monitor. - Log Analytics API: Leave as
Azure Log Analytics(even if you’re not using Log Analytics yet, it’s good to have this enabled for future use). - Click "Save & Test". You should see a "Data source is working" message.
- Name:
Let’s query some metrics. Create a new dashboard or open an existing one. Add a panel, and select your Azure Monitor data source.
In the query editor:
- Service:
Azure Monitor - Resource Group: Select the resource group containing your VMs, App Services, etc.
- Resource: Select a specific resource, e.g., a Virtual Machine.
- Namespace:
Microsoft.Compute/virtualMachines - Metric:
Percentage CPU - Aggregation:
Average
This will fetch the average CPU percentage for that VM over the selected time range.
You can also query Log Analytics data if you’ve configured that too. For example, to see the count of Heartbeat logs in the last hour:
- Service:
Azure Log Analytics - Workspace: Select your Log Analytics workspace.
- Query:
Heartbeat | where TimeGenerated > ago(1h) | count
The real power comes from the Azure Monitor query editor’s ability to select "Resource Type" and then "Resource" dynamically. For instance, if you select Microsoft.Web/sites as the Resource Type, the "Resource" dropdown will populate with your App Services. You can then choose metrics like Http Server Errors or Requests.
When you select a metric, Grafana automatically fetches the available aggregations (Average, Sum, Count, Min, Max). You can also choose "Count" to see how many data points were collected for that metric in a given interval, which can be useful for debugging data gaps.
The most surprising thing about the Azure Monitor data source is its ability to query across resource groups and subscriptions, if your Service Principal has the necessary IAM roles assigned at those higher scopes. This means you can build dashboards that aggregate metrics from dozens or hundreds of resources without needing to specify each one individually in your queries. Instead, you can use the Resource field to select "All" or use the "Resource Group" field to select multiple groups, and Grafana will pull data for all matching resources.
The next thing you’ll likely want to explore is using Grafana’s templating features to dynamically select subscriptions, resource groups, and resources directly on your dashboard, making your dashboards reusable and interactive.