Database Metrics, Logs and Alerts
This lesson explains platform metrics, diagnostic settings, Log Analytics queries and alerts for Azure SQL databases.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish between platform metrics and resource logs.
- Choose a diagnostic setting destination and log categories.
- Describe metric and log search alerts.
Platform metrics
Azure SQL Database emits platform metrics automatically every minute, with no configuration: CPU percentage, data IO percentage, log IO percentage, workers and sessions percentage, storage used, connections (successful, failed and blocked by firewall), deadlocks, and for serverless and the free offer, app CPU billed and free amount remaining. Metrics are kept for 93 days and can be charted in Metrics explorer, pinned to dashboards and used in alerts.
Platform metrics
Diagnostic settings and Log Analytics
Diagnostic settings send resource logs and metrics to destinations: a Log Analytics workspace for querying, a storage account for archiving or Event Hubs for streaming. The log categories for an Azure SQL database are listed in the following table.
| Category | Contains |
|---|---|
| SQLInsights | Intelligent Insights performance diagnostics |
| AutomaticTuning | Automatic tuning recommendations and actions |
| QueryStoreRuntimeStatistics and QueryStoreWaitStatistics | Query Store runtime and wait data |
| Errors | Errors raised by the database |
| DatabaseWaitStatistics | Time spent in each wait type |
| Timeouts | Query timeouts |
| Blocks | Blocking events |
| Deadlocks | Deadlock graphs |
Logs in a workspace are queried with KQL. Resource-specific destination tables are recommended over the legacy AzureDiagnostics table because they have typed columns and better performance. Log ingestion is billed per GB, so only the categories that answer real questions should be enabled, and basic or auxiliary table plans can lower the cost of verbose logs.
// Deadlocks in the last day, per database
AzureDiagnostics
| where Category == "Deadlocks" and TimeGenerated > ago(1d)
| summarize Deadlocks = count() by Resource, bin(TimeGenerated, 1h)Diagnostic log categories
Alerts and deeper monitoring
Metric alert rules fire when a metric crosses a threshold, for example CPU above 80% for 15 minutes or deadlocks greater than zero, and log search alert rules run a KQL query on a schedule. Both notify through action groups (email, SMS, webhooks, Logic Apps or Functions). For an estate of databases, database watcher collects detailed monitoring data, such as query, wait and resource statistics, into Azure Data Explorer or Real-Time Intelligence in Fabric with ready-made dashboards. For the free offer, an alert on the free amount remaining metric warns before the monthly allowance runs out.
Alerts and monitoring
Alerting on blocking
Operations wants a notification when blocking events in a production Azure SQL database exceed 10 in five minutes, and the team wants to analyse blocking history with KQL. What should the developer configure?
Create a diagnostic setting that sends the Blocks category (and Deadlocks, if useful) to a Log Analytics workspace, then create a log search alert rule with a KQL query that counts blocking events over five minutes and an action group that notifies operations. Platform metrics do not include a blocking count, and archiving to a storage account does not allow KQL queries or log alerts.
Do resource logs such as Deadlocks reach Log Analytics automatically?
Show answer
No. Platform metrics are automatic, but resource logs need a diagnostic setting.
Exam Tips
Remember for the exam
- Platform metrics are automatic; resource logs need diagnostic settings.
- KQL and log alerts: Log Analytics destination; archive: storage; streaming: Event Hubs.
- Blocking and deadlock history: Blocks and Deadlocks categories.
- Enable only needed categories; log ingestion is billed per GB.