Skip to main content

Azure Monitor & Log Analytics

The Monitoring Architecture

Azure Monitor Architecture
Monitoring Architecture
📊
Metrics
Numeric time-series (CPU %, DTU %, sessions). Near real-time (~1 min). Free. 93-day retention.
📝
Logs
Structured event records (audit, errors, query stats). KQL queryable. Per-GB cost. 30-730 days.
🚨
Alerts
Metric alerts (real-time thresholds), Log alerts (KQL queries), Activity log alerts (control plane).

Metrics vs Logs

MetricsLogs
WhatNumeric time-series dataStructured event records
LatencyNear real-time (~1 min)2-5 minutes ingestion
Retention93 days (standard)30-730 days (configurable)
QueryMetrics Explorer (charts)KQL (Kusto Query Language)
CostFree (platform metrics)Per GB ingested
ExamplesCPU %, DTU %, sessionsAudit logs, query stats, errors

Key SQL Database Metrics

MetricWhat It MeansAlert Threshold
cpu_percentCPU utilization> 80% sustained
dtu_consumption_percentDTU usage (DTU model)> 80%
physical_data_read_percentData I/O utilization> 80%
log_write_percentLog I/O utilization> 80%
sessions_percentActive sessions vs limit> 80%
workers_percentActive workers vs limit> 70%
deadlockDeadlock count> 0
storage_percentDatabase size vs max> 85%
connection_failedFailed connection count> 10/min
🎯 Exam Focus

Metrics alerts are near real-time — perfect for "alert me when CPU > 80%". Log alerts use KQL queries — perfect for "alert me when a specific error appears" or "when a query takes > 5 seconds". Know when to use which.

Log Analytics — KQL Essentials

KQL (Kusto Query Language) is the query language for Log Analytics. Think of it as SQL for logs.

KQL vs SQL Comparison

SQLKQL Equivalent
SELECT * FROM table WHERE col = 'x'Table | where col == "x"
SELECT TOP 10 * FROM tableTable | take 10
SELECT col, COUNT(*) GROUP BY colTable | summarize count() by col
ORDER BY col DESC| sort by col desc
DISTINCT col| distinct col

Key KQL for Database Monitoring

// Top 10 slowest queries (from diagnostics)
AzureDiagnostics
| where Category == "QueryStoreRuntimeStatistics"
| summarize avg(duration_d) by query_id_d
| top 10 by avg_duration_d desc

// Failed connections in last hour
AzureDiagnostics
| where Category == "SQLSecurityAuditEvents"
| where action_name_s == "DATABASE AUTHENTICATION FAILED"
| where TimeGenerated > ago(1h)
| summarize count() by client_ip_s
| sort by count_ desc

// DTU usage over time
AzureMetrics
| where MetricName == "dtu_consumption_percent"
| summarize avg(Average) by bin(TimeGenerated, 5m)
| render timechart
🏢 Real-World DBA Note

Oracle DBA parallel: KQL is to Log Analytics what SQL is to Oracle's Unified Audit trail, but more powerful. You can query across multiple Azure services in one workspace — imagine querying SQL audit logs, App Service logs, and Key Vault logs in one query.

Alert Architecture

Alert Architecture
📊
Signal Source
Metric (CPU > 80%)
Log query (KQL result)
Activity log event
🎯
Alert Rule
Condition: threshold, frequency, severity
Evaluation window and aggregation
📣
Action Group
Reusable notification targets
Email, SMS, webhook, Teams, runbook
🔔
Notification
Alert fires and triggers action group
DBA team notified via configured channels

Alert Types

TypeSignalExampleLatency
Metric alertNumeric metricCPU > 80% for 5 min~1 minute
Log alertKQL query resultDeadlocks > 5 in 10 min~5 minutes
Activity log alertControl plane eventDatabase deleted~1 minute
Smart detectionML anomalyUnusual query duration spikeMinutes
🎯 Exam Focus

Action Groups are reusable — one action group can be attached to multiple alert rules. This is the Azure pattern for "notify the DBA team" — create one action group with email + SMS + Teams webhook, then attach it to all your alert rules.

Diagnostic Settings

To get logs into Log Analytics, you must configure Diagnostic Settings on each resource:

Diagnostic Settings
🗄️
Azure SQL Resource
SQL Database, MI, or SQL VM
Emits metrics + diagnostic logs
⚙️
Configure Diagnostic Settings
Select log categories (QueryStore, Errors, Deadlocks, etc.)
Choose one or more destinations
📊
Destinations
Log Analytics (KQL queries + dashboards)
Storage Account (long-term archival)
Event Hub (real-time SIEM streaming)

Available SQL Diagnostic Categories

CategoryWhat It Contains
SQLInsightsIntelligent Insights analysis
AutomaticTuningAuto-tuning recommendations and actions
QueryStoreRuntimeStatisticsQuery performance data
QueryStoreWaitStatisticsWait stats per query
ErrorsDatabase errors
DatabaseWaitStatisticsAggregate wait stats
TimeoutsQuery timeouts
BlocksBlocking events
DeadlocksDeadlock graphs

What is the difference between Azure Metrics and Logs?
Click to reveal answer
Metrics = numeric time-series (near real-time, free, 93-day retention). Logs = structured events (KQL queryable, per-GB cost, 30-730 day retention).
1 / 6

Q1/3
0 correct
You need to alert the DBA team when CPU exceeds 80% for more than 5 minutes. What Alert type should you use?