Log Analytics, KQL and Application Insights: Query Logs, Build Workbooks and Monitor Applications
Log Analytics Workspace
bash
az monitor log-analytics workspace create -g rg-ops -n law-ops --location centralindia --retention-time 90
az monitor log-analytics workspace show -g rg-ops -n law-ops --query "{id:id, customerId:customerId, retention:retentionInDays}"
- Stores log data in tables (for example
Heartbeat,Perf,AzureActivity,Syslog,Event) - You pay by GB ingested and retention. Choose retention per table when needed
- Use resource-context RBAC so teams see only their resources' logs
Connect VMs
- Install the Azure Monitor Agent (AMA) extension on the VM
- Create a data collection rule (DCR) choosing what to collect (performance counters, Windows events, Syslog)
- Associate the DCR with the VMs
- Turn on VM insights for maps and performance charts
AMA replaces the older Log Analytics (MMA/OMS) agent. Check the current guidance when you see older documents.
KQL Basics
Each step passes rows to the next step with the pipe |.
kql
// All VMs that sent a heartbeat in the last 10 minutes
Heartbeat
| where TimeGenerated > ago(10m)
| summarize last = max(TimeGenerated) by Computer
// Average CPU per computer, 5-minute buckets
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| where TimeGenerated > ago(1h)
| summarize avgCpu = avg(CounterValue) by Computer, bin(TimeGenerated, 5m)
| render timechart
// Who deleted resources in the last 7 days
AzureActivity
| where TimeGenerated > ago(7d) and OperationNameValue endswith "DELETE" and ActivityStatusValue == "Success"
| project TimeGenerated, Caller, Resource, ResourceGroup
| Operator | Use |
|---|---|
where | Filter rows |
project | Choose columns |
extend | Add computed columns |
summarize ... by | Group and calculate (count, avg, max, dcount) |
order by / top | Sort and limit |
join / union | Combine tables |
render | Draw a chart |
ago(), bin() | Time helpers |
Save and Use Queries
- Save queries and share in query packs
- Pin results to dashboards or build workbooks that mix text, queries and charts
- Create a log search alert from a query (for example more than 5 errors in 5 minutes)
Application Insights
- Application performance monitoring for web apps and APIs: requests, dependencies, exceptions, response times, users
- Create it workspace-based (data lands in Log Analytics)
- Enable for App Service with one click or add the OpenTelemetry-based Azure Monitor SDK for your language
- Features: Application map, Live metrics, Availability tests (ping tests from many locations), Failures and Performance views
kql
requests
| where timestamp > ago(1h)
| summarize total = count(), failed = countif(success == false), p95 = percentile(duration, 95) by name
| order by failed desc
Practice
- Create a workspace and connect a VM with AMA
- Run a query for CPU per computer and render a chart
- Create a log alert for repeated failures
- Add an availability test for a web app
Conclusion
Log Analytics stores logs you query with KQL. Use AMA and data collection rules to bring in VM data, workbooks to present it and Application Insights to monitor your applications.
Quick Summary: workspace; connect VMs; KQL; saving; Application Insights.

