Monitoring Azure SQL Virtual Machines

Learn how to monitor performance, health, and usage of your Azure SQL Virtual Machines using Azure Monitor, Log Analytics, and PowerShell.

On this page

Overview

Azure SQL Virtual Machines integrate with Azure Monitor to provide metrics, alerts, and log analytics. This tutorial walks through enabling monitoring, exploring built‑in metrics, setting up alerts, and using Log Analytics queries.

Prerequisites

Enable Azure Monitor for SQL VM

Use the Azure portal or Azure CLI to enable the Monitoring extension.

az vm extension set \
    --publisher Microsoft.Azure.Diagnostics \
    --name AzureDiagnostics \
    --resource-group MyResourceGroup \
    --vm-name MySqlVM \
    --settings '{"protectedSettings": {"storageAccountName": "mystorageacct"}}'

View Metrics in Azure Portal

Navigate to your SQL VM resource, then select Metrics under Monitoring.

Key metrics:

Metrics screenshot

Configure Alerts

Create an alert rule to get notified when CPU usage exceeds 80% for 5 minutes.

az monitor metrics alert create \
    --name HighCpuAlert \
    --resource-group MyResourceGroup \
    --scopes $(az vm show -g MyResourceGroup -n MySqlVM --query id -o tsv) \
    --condition "max Percentage CPU > 80" \
    --description "Alert when CPU > 80%" \
    --action-group MyActionGroup

Collect Logs with Log Analytics

Link your SQL VM to a Log Analytics workspace to query performance logs.

# Link VM to Log Analytics workspace
az vm diagnostics set \
    --resource-group MyResourceGroup \
    --vm-name MySqlVM \
    --workspace MyLogAnalyticsWorkspace

Sample Kusto query to retrieve average CPU usage per hour:

Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| summarize AvgCPU = avg(CounterValue) by bin(TimeGenerated, 1h), Computer
| order by TimeGenerated desc

Monitor with PowerShell

Retrieve VM metrics via the Az module.

# Install Az module if needed
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

# Connect to Azure
Connect-AzAccount

# Get CPU metric
Get-AzMetric -ResourceId (Get-AzVM -Name MySqlVM -ResourceGroupName MyResourceGroup).Id `
    -MetricName "Percentage CPU" -TimeGrain "PT1M" -StartTime (Get-Date).AddHours(-1) -EndTime (Get-Date)

For more advanced monitoring scenarios, refer to the Logging tutorial.