1---2name: azure-monitor3description: Use when setting up Azure observability with Log Analytics, configuring metric and log alerts, integrating Application Insights for APM, routing diagnostic logs, or studying for AZ-400 or AZ-305.4---56# Azure Monitor78## When to Use9- Setting up centralized logging and monitoring for Azure resources10- Querying logs with KQL in Log Analytics workspace11- Configuring metric alerts and log search alerts with action groups12- Integrating Application Insights for web application APM13- Routing resource diagnostic logs to Log Analytics, Storage, or Event Hub14- Preparing for Azure DevOps Engineer Expert (AZ-400) or AZ-305 exam1516## Core Jobs1718### 1. Azure Monitor Data Types and Sources19| Data Type | Description | Retention | Tool |20|-----------|-------------|-----------|------|21| **Metrics** | Numeric time-series (CPU %, request count) | 93 days | Metrics Explorer |22| **Logs** | Structured records (events, traces, exceptions) | 30 days default (configurable to 2 years) | Log Analytics |23| **Traces** | Distributed tracing across services | Application Insights | Application Insights |24| **Changes** | Resource configuration changes | Azure Resource Graph | Change Analysis |2526- **Metrics** = lightweight, near-real-time; good for dashboards and threshold alerts27- **Logs** = rich structured data; query with KQL; better for investigation and custom alerting2829### 2. Log Analytics Workspace30- Central store for all log data across Azure and on-premises31- **KQL (Kusto Query Language)** for querying:32 ```kql33 // Requests in last 1 hour, bucketed by 5 minutes34 requests35 | where timestamp > ago(1h)36 | summarize count() by bin(timestamp, 5m)37 | render timechart3839 // Errors grouped by operation40 exceptions41 | where timestamp > ago(24h)42 | summarize count() by outerMessage43 | order by count_ desc44 ```45- **Workspace design**: one workspace per environment (or region) is common; cross-workspace queries supported46- **Table retention**: default 30 days; configure per-table (Basic logs = 30 days, cheap; Analytics logs = full KQL, more expensive)47- **Commitment tiers**: pay-per-GB (default) or commitment tier (e.g., 100 GB/day) for cost predictability4849### 3. Application Insights50- **APM** = Application Performance Monitoring for web apps51- Tracks: HTTP requests, dependencies (SQL, HTTP), exceptions, custom events, page views, user flows52- Integration: SDK-based (add ApplicationInsights SDK) or auto-instrumentation (Azure App Service)53- Key features:54 - **Live Metrics**: real-time request and failure count55 - **Application Map**: visual dependency graph with failure rate per component56 - **Smart Detection**: ML-based anomaly detection on failure rate, response time57 - **Availability tests**: periodic synthetic requests from multiple regions58- **Sampling**: reduces telemetry volume; adaptive (auto-adjusts) or fixed-rate; does not affect metrics5960### 4. Diagnostic Settings61- Every Azure resource can emit **platform logs** and **metrics** via Diagnostic Settings62- Destinations (one or more per resource):63 - **Log Analytics workspace** — for KQL querying and alerting64 - **Storage Account** — for archival (compliance, long-term)65 - **Event Hub** — for streaming to SIEM or external monitoring (Sentinel, Splunk)66- Log categories vary by resource (e.g., Storage: StorageRead, StorageWrite, StorageDelete)67- **Activity Log** = subscription-level audit log (who did what, when); auto-available; route to workspace for querying6869### 5. Alerts70| Alert Type | Based On | Good For |71|------------|----------|---------|72| **Metric alert** | Metric threshold or dynamic baseline | CPU > 80%, response time spike |73| **Log search alert** | KQL query result count or value | Error count, specific log pattern |74| **Activity Log alert** | Azure resource operation | "VM deleted", "policy assignment changed" |75| **Smart Detection** | ML anomaly (App Insights) | Automatic failure rate anomaly |7677- **Action groups**: reusable set of notification/automation actions (email, SMS, webhook, Logic App, Function, ITSM)78- **Alert processing rules**: suppress alerts during maintenance windows; route to different action groups79- Alert states: Fired → Acknowledged → Resolved8081### 6. Workbooks82- Interactive parameterized dashboards combining metrics, logs, and visualizations83- Template gallery: available for common services (AKS, App Service, Storage)84- Share with team; supports time range parameters, subscription/resource filters85- Use for: operational dashboards, cost analysis, security posture reports8687## Key Concepts88- **Azure Monitor** — platform umbrella; collects metrics + logs; powers alerts, dashboards, Application Insights89- **Log Analytics** — log store + KQL query engine; workspace-based; central for all resource logs90- **Application Insights** — APM component of Azure Monitor; SDK or auto-instrumentation; requests, dependencies, exceptions91- **Diagnostic settings** — must configure per resource to route platform logs to Log Analytics/Storage/Event Hub92- **Action group** — reusable notification target for alerts (email, webhook, Logic App)93- **KQL** — Kusto Query Language; `| where`, `| summarize`, `| project`, `| render`; same as Sentinel and Fabric9495## Checklist96- [ ] Log Analytics workspace created and diagnostic settings configured for critical resources?97- [ ] Application Insights integrated for all web applications (SDK or auto-instrumentation)?98- [ ] Metric alerts configured for key health indicators (CPU, memory, response time, error rate)?99- [ ] Log search alert for application errors (exceptions > threshold per 5 minutes)?100- [ ] Activity Log routed to Log Analytics for audit and alerting on resource changes?101- [ ] Action group configured with appropriate notification channels (email, Teams webhook)?102- [ ] Alert processing rules created to suppress alerts during planned maintenance?103104## Output Format105- 🔴 **Critical** — no diagnostic settings configured on critical resources (logs not collected; blind to failures)106- 🔴 **Critical** — no alerts on application error rate (failures go undetected until user reports)107- 🟡 **Warning** — Log Analytics on pay-per-GB without commitment tier for predictable high-volume ingestion108- 🟡 **Warning** — Application Insights sampling disabled on high-traffic app (cost overrun risk)109- 🟢 **Suggestion** — enable Smart Detection in Application Insights for automatic anomaly alerting110111## Exam Tips112- **Azure Monitor = platform; Log Analytics = log store; Application Insights = APM** — they are layered: Application Insights sits on top of Azure Monitor; Log Analytics is the storage engine113- **KQL `| where TimeGenerated > ago(1h) | summarize count() by bin(TimeGenerated, 5m)`** — standard pattern for time-bucketed log analysis114- **Diagnostic settings = must configure per resource** — not automatic; each resource needs its own diagnostic setting to route logs to Log Analytics115- **Alert processing rules** — suppress alerts during maintenance windows or route to different action groups; separate from alert rules116- **Application Insights sampling** — reduces telemetry volume; adaptive (auto) or fixed rate; does NOT affect metrics count (only detailed records)117- **Log Analytics workspace** — centralize logs from multiple subscriptions; cross-workspace queries possible with `union workspace("ws2").TableName`