Monitor Azure SQL Database using Azure SQL Analytics (preview)
APPLIES TO: Azure SQL Database, Azure SQL Managed Instance
Caution
Azure SQL Analytics (preview) is an integration with Azure Monitor, where many monitoring solutions are no longer in active development. For more monitoring options, see Monitoring and performance tuning in Azure SQL Database and Azure SQL Managed Instance.
Azure SQL Analytics (preview) is an advanced cloud monitoring solution for monitoring performance of all of your Azure SQL databases at scale and across multiple subscriptions in a single view. Azure SQL Analytics collects and visualizes key performance metrics with built-in intelligence for performance troubleshooting.
By using these collected metrics, you can create custom monitoring rules and alerts. Azure SQL Analytics helps you to identify issues at each layer of your application stack. Azure SQL Analytics uses Azure Diagnostics metrics along with Azure Monitor views to present data about all your Azure SQL databases in a single Log Analytics workspace. Azure Monitor helps you to collect, correlate, and visualize structured and unstructured data.
Connected sources
Azure SQL Analytics is a cloud-only monitoring solution supporting streaming of diagnostics telemetry for all of your Azure SQL databases. Because Azure SQL Analytics does not use agents to connect to Azure Monitor, it does not support monitoring of SQL Server hosted on-premises or in virtual machines.
Connected Source | Supported | Description |
---|---|---|
Diagnostics settings | Yes | Azure metric and log data are sent to Azure Monitor Logs directly by Azure. |
Azure storage account | No | Azure Monitor doesn't read the data from a storage account. |
Windows agents | No | Direct Windows agents aren't used by Azure SQL Analytics. |
Linux agents | No | Direct Linux agents aren't used by Azure SQL Analytics. |
System Center Operations Manager management group | No | A direct connection from the Operations Manager agent to Azure Monitor is not used by Azure SQL Analytics. |
Azure SQL Analytics options
The below table outlines supported options for two versions of the Azure SQL Analytics dashboard, one for Azure SQL Database, and the other one for Azure SQL Managed Instance databases.
Azure SQL Analytics option | Description | SQL Database support | SQL Managed Instance support |
---|---|---|---|
Resource by type | Perspective that counts all the resources monitored. | Yes | Yes |
Insights | Provides hierarchical drill-down into Intelligent Insights into performance. | Yes | Yes |
Errors | Provides hierarchical drill-down into SQL errors that happened on the databases. | Yes | Yes |
Timeouts | Provides hierarchical drill-down into SQL timeouts that happened on the databases. | Yes | No |
Blockings | Provides hierarchical drill-down into SQL blockings that happened on the databases. | Yes | No |
Database waits | Provides hierarchical drill-down into SQL wait statistics on the database level. Includes summaries of total waiting time and the waiting time per wait type. | Yes | No |
Query duration | Provides hierarchical drill-down into the query execution statistics such as query duration, CPU usage, Data IO usage, Log IO usage. | Yes | Yes |
Query waits | Provides hierarchical drill-down into the query wait statistics by wait category. | Yes | Yes |
Configuration of Azure SQL Analytics (preview)
Use the process described in Add Azure Monitor solutions from the Solutions Gallery to add Azure SQL Analytics (Preview) to your Log Analytics workspace.
Configure Azure SQL Database to stream diagnostics telemetry
Once you have created Azure SQL Analytics solution in your workspace, you need to configure each resource that you want to monitor to stream its diagnostics telemetry to Azure SQL Analytics. Follow detailed instructions on this page:
- Enable Azure Diagnostics for your database to stream diagnostics telemetry to Azure SQL Analytics.
The above page also provides instructions on enabling support for monitoring multiple Azure subscriptions from a single Azure SQL Analytics workspace as a single pane of glass.
Use Azure SQL Analytics (preview)
Navigate to your SQL Analytics deployment from the Legacy solutions page of the Log Analytics workspace.
Azure SQL Analytics provides two separate views: one for monitoring SQL Database, and the other view for monitoring SQL Managed Instance.
Viewing Azure SQL Analytics data
The dashboard includes the overview of all databases that are monitored through different perspectives. For different perspectives to work, you must enable proper metrics or logs on your SQL resources to be streamed to Log Analytics workspace.
If some metrics or logs are not streamed into Azure Monitor, the tiles in Azure SQL Analytics are not populated with monitoring information.
SQL Database view
Once the Azure SQL Analytics tile for the database is selected, the monitoring dashboard is shown.
Selecting any of the tiles, opens a drill-down report into the specific perspective. Once the perspective is selected, the drill-down report is opened.
Each perspective in this view provides summaries at the subscription, server, elastic pool, and database levels. In addition, each perspective shows a perspective specific to the report on the right. Selecting subscription, server, pool, or database from the list continues the drill-down.
SQL Managed Instance view
Once the Azure SQL Analytics tile for the databases is selected, the monitoring dashboard is shown.
Selecting any of the tiles, opens a drill-down report into the specific perspective. Once the perspective is selected, the drill-down report is opened.
Selecting the SQL Managed Instance view, shows details on the instance utilization, instance databases, and telemetry on the queries executed across the managed instance.
Intelligent Insights report
Azure SQL Database Intelligent Insights lets you know what is happening with performance of all Azure SQL databases. All Intelligent Insights collected can be visualized and accessed through the Insights perspective.
Elastic pools and database reports
Both elastic pools and databases have their own specific reports that show all the data that is collected for the resource in the specified time.
Query reports
Through the query duration and query waits perspectives, you can correlate the performance of any query through the query report. This report compares the query performance across different databases and makes it easy to pinpoint databases that perform the selected query well versus ones that are slow.
Permissions
To use Azure SQL Analytics (preview), users need to be granted a minimum permission of the Reader role in Azure. This role, however, does not allow users to see the query text, or perform any Automatic tuning actions. More permissive roles in Azure that allow using Azure SQL Analytics to the fullest extent are Owner, Contributor, SQL DB Contributor, or SQL Server Contributor. You also might want to consider creating a custom role in the portal with specific permissions required only to use Azure SQL Analytics, and with no access to managing other resources.
Create a custom role in portal
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Recognizing that some organizations enforce strict permission controls in Azure, find the following PowerShell script enabling creation of a custom role "SQL Analytics Monitoring Operator" in Azure portal with the minimum read and write permissions required to use Azure SQL Analytics to its fullest extent.
Replace the "{SubscriptionId}" in the below script with your Azure subscription ID, and execute the script logged in as an Owner or Contributor role in Azure.
Connect-AzAccount
Select-AzSubscription {SubscriptionId}
$role = Get-AzRoleDefinition -Name Reader
$role.Name = "SQL Analytics Monitoring Operator"
$role.Description = "Lets you monitor database performance with Azure SQL Analytics as a reader. Does not allow change of resources."
$role.IsCustom = $true
$role.Actions.Add("Microsoft.SQL/servers/databases/read");
$role.Actions.Add("Microsoft.SQL/servers/databases/topQueries/queryText/*");
$role.Actions.Add("Microsoft.Sql/servers/databases/advisors/read");
$role.Actions.Add("Microsoft.Sql/servers/databases/advisors/write");
$role.Actions.Add("Microsoft.Sql/servers/databases/advisors/recommendedActions/read");
$role.Actions.Add("Microsoft.Sql/servers/databases/advisors/recommendedActions/write");
$role.Actions.Add("Microsoft.Sql/servers/databases/automaticTuning/read");
$role.Actions.Add("Microsoft.Sql/servers/databases/automaticTuning/write");
$role.Actions.Add("Microsoft.Sql/servers/advisors/read");
$role.Actions.Add("Microsoft.Sql/servers/advisors/write");
$role.Actions.Add("Microsoft.Sql/servers/advisors/recommendedActions/read");
$role.Actions.Add("Microsoft.Sql/servers/advisors/recommendedActions/write");
$role.Actions.Add("Microsoft.Resources/deployments/write");
$role.AssignableScopes = "/subscriptions/{SubscriptionId}"
New-AzRoleDefinition $role
Once the new role is created, assign this role to each user that you need to grant custom permissions to use Azure SQL Analytics.
Analyze data and create alerts
Data analysis in Azure SQL Analytics is based on Log Analytics language for your custom querying and reporting. Find description of the available data collected from database resource for custom querying in metrics and logs available.
Automated alerting in Azure SQL Analytics is based on writing a Log Analytics query that triggers an alert upon a condition met. Find below several examples on Log Analytics queries upon which alerting can be set up in Azure SQL Analytics.
Create alerts for Azure SQL Database
You can easily create alerts with the data coming from Azure SQL Database resources. Here are some useful log queries that you can use with a log alert:
High CPU
AzureMetrics
| where ResourceProvider=="MICROSOFT.SQL"
| where ResourceId contains "/DATABASES/"
| where MetricName=="cpu_percent"
| summarize AggregatedValue = max(Maximum) by bin(TimeGenerated, 5m)
| render timechart
Note
- Pre-requirement of setting up this alert is that monitored databases stream basic metrics to the Log Analytics workspace used by Azure SQL Analytics.
- Replace the MetricName value
cpu_percent
withdtu_consumption_percent
to obtain high DTU results instead.
High CPU on elastic pools
AzureMetrics
| where ResourceProvider=="MICROSOFT.SQL"
| where ResourceId contains "/ELASTICPOOLS/"
| where MetricName=="cpu_percent"
| summarize AggregatedValue = max(Maximum) by bin(TimeGenerated, 5m)
| render timechart
Note
- Pre-requirement of setting up this alert is that monitored databases stream Basic metrics to the Log Analytics workspace used by Azure SQL Analytics.
- Replace the MetricName value
cpu_percent
withdtu_consumption_percent
to obtain high DTU results instead.
Storage in average above 95% in the last 1 hr
let time_range = 1h;
let storage_threshold = 95;
AzureMetrics
| where ResourceId contains "/DATABASES/"
| where MetricName == "storage_percent"
| summarize max_storage = max(Average) by ResourceId, bin(TimeGenerated, time_range)
| where max_storage > storage_threshold
| distinct ResourceId
Note
- Pre-requirement of setting up this alert is that monitored databases stream basic metrics to the Log Analytics workspace used by Azure SQL Analytics.
- This query requires an alert rule to be set up to fire off an alert when there exist results (> 0 results) from the query, denoting that the condition exists on some databases. The output is a list of database resources that are above the
storage_threshold
within thetime_range
defined. - The output is a list of database resources that are above the
storage_threshold
within thetime_range
defined.
Alert on Intelligent insights
Important
In case a database is performing well, and that no Intelligent Insights have been generated, this query will fail with an error message: Failed to resolve scalar expression named rootCauseAnalysis_s
. This behavior is expected for all cases where there exist no intelligent insights for the database.
let alert_run_interval = 1h;
let insights_string = "hitting its CPU limits";
AzureDiagnostics
| where Category == "SQLInsights" and status_s == "Active"
| where TimeGenerated > ago(alert_run_interval)
| where rootCauseAnalysis_s contains insights_string
| distinct ResourceId
Note
- Pre-requirement of setting up this alert is that monitored databases stream SQLInsights diagnostics log to the Log Analytics workspace used by Azure SQL Analytics.
- This query requires an alert rule to be set up to run with the same frequency as
alert_run_interval
in order to avoid duplicate results. The rule should be set up to fire off the alert when there exist results (> 0 results) from the query. - Customize the
alert_run_interval
to specify the time range to check if the condition has occurred on databases configured to stream SQLInsights log to Azure SQL Analytics. - Customize the insights_string to capture the output of the Insights root cause analysis text. This is the same text displayed in the UI of Azure SQL Analytics that you can use from the existing insights. Alternatively, you can use the query below to see the text of all Insights generated on your subscription. Use the output of the query to harvest the distinct strings for setting up alerts on Insights.
AzureDiagnostics
| where Category == "SQLInsights" and status_s == "Active"
| distinct rootCauseAnalysis_s
Create alerts for SQL Managed Instance
Storage is above 90%
let storage_percentage_threshold = 90;
AzureDiagnostics
| where Category =="ResourceUsageStats"
| summarize (TimeGenerated, calculated_storage_percentage) = arg_max(TimeGenerated, todouble(storage_space_used_mb_s) *100 / todouble (reserved_storage_mb_s))
by ResourceId
| where calculated_storage_percentage > storage_percentage_threshold
Note
- Pre-requirement of setting up this alert is that the monitored managed instance has the streaming of ResourceUsageStats log enabled to the Log Analytics workspace used by Azure SQL Analytics.
- This query requires an alert rule to be set up to fire off an alert when there exist results (> 0 results) from the query, denoting that the condition exists on the managed instance. The output is storage percentage consumption on the managed instance.
CPU average consumption is above 95% in the last 1 hr
let cpu_percentage_threshold = 95;
let time_threshold = ago(1h);
AzureDiagnostics
| where Category == "ResourceUsageStats" and TimeGenerated > time_threshold
| summarize avg_cpu = max(todouble(avg_cpu_percent_s)) by ResourceId
| where avg_cpu > cpu_percentage_threshold
Note
- Pre-requirement of setting up this alert is that the monitored managed instance has the streaming of ResourceUsageStats log enabled to the Log Analytics workspace used by Azure SQL Analytics.
- This query requires an alert rule to be set up to fire off an alert when there exist results (> 0 results) from the query, denoting that the condition exists on the managed instance. The output is average CPU utilization percentage consumption in defined period on the managed instance.
Pricing
While Azure SQL Analytics (preview) is free to use, consumption of diagnostics telemetry above the free units of data ingestion allocated each month applies, see Log Analytics pricing. The free units of data ingestion provided enable free monitoring of several databases each month. More active databases with heavier workloads ingest more data versus idle databases. You can easily monitor your data ingestion consumption in Azure SQL Analytics by selecting OMS Workspace on the navigation menu of Azure SQL Analytics, and then selecting Usage and Estimated Costs.
Next steps
- Use log queries in Azure Monitor to view detailed Azure SQL data.
- Create your own dashboards showing Azure SQL data.
- Create alerts when specific Azure SQL events occur.
- Monitor Azure SQL Database with Azure Monitor
- Monitor Azure SQL Managed Instance with Azure Monitor