Querying Logs with Kusto Query Language
This lesson explains the structure of KQL queries, common tables and operators, and how queries are used.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the structure of a KQL query.
- Explain the purpose of common tables and operators.
- Interpret simple KQL queries.
Query structure
A KQL query starts with a table name and passes rows through a series of operators separated by the pipe character. Each operator takes the output of the previous one. Queries run on the Logs page of a workspace (all data in it) or of a resource (only data about that resource), within the time range picker unless the query filters TimeGenerated itself. Common tables include those below.
| Table | Contents |
|---|---|
| AzureActivity | Activity log: control plane operations and who performed them |
| Heartbeat | One row per minute from each machine with the Azure Monitor Agent |
| Perf / InsightsMetrics | Performance counters from VMs (Perf from DCRs, InsightsMetrics from VM insights) |
| Event / Syslog | Windows event logs and Linux syslog |
| AzureDiagnostics and resource-specific tables | Resource logs, such as StorageBlobLogs or AzureFirewallNetworkRule |
| SigninLogs / AuditLogs | Microsoft Entra sign-ins and directory changes |
Which table?
Essential operators
where filters rows by a condition; project chooses and renames columns; extend adds calculated columns; summarize aggregates with functions such as count(), avg(), max(), dcount() and arg_max(), grouped by columns or time bins (bin(TimeGenerated, 1h)); sort by and top order results; take returns sample rows; join and union combine tables; and render draws a chart. ago(1d) and now() express relative times. The following queries are typical administration examples.
// Who deleted resources in the last 7 days?
AzureActivity
| where TimeGenerated > ago(7d)
| where OperationNameValue endswith "DELETE" and ActivityStatusValue == "Success"
| project TimeGenerated, Caller, ResourceGroup, _ResourceId
// Average CPU per computer in 15-minute bins, as a chart
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| summarize AvgCPU = avg(CounterValue) by Computer, bin(TimeGenerated, 15m)
| render timechart
// Machines that have not reported for 15 minutes
Heartbeat
| summarize LastSeen = max(TimeGenerated) by Computer
| where LastSeen < ago(15m)
// Failed storage requests by operation and status
StorageBlobLogs
| where StatusCode >= 400
| summarize Failures = count() by OperationName, StatusText
| sort by Failures descThe following diagram shows a KQL query that counts Windows error events per computer, and the shape of its result.

Building a query
Using query results
Queries can be saved in a workspace or in query packs, pinned to dashboards, added to workbooks with parameters and visualizations, exported to Excel or Power BI, and used as the condition of log search alert rules, which run a query on a schedule and fire when the number of results or a measured value crosses a threshold. The portal's Queries hub offers examples for each resource type, and simple mode builds queries without writing KQL.
Using queries
Reading a query
An administrator runs the query Event | where EventLevelName == "Error" | summarize count() by Computer | where count_ > 50 | sort by count_ desc over the last 24 hours. What does it return, and what must be in place for the Event table to contain data?
It returns one row per computer that logged more than 50 Windows error events in the period, with the count, sorted from most to fewest. The Event table is populated only if the VMs have the Azure Monitor Agent and a data collection rule that collects Windows event logs at the Error level and sends them to this workspace.
Which KQL operator aggregates rows, for example counting events per computer?
Show answer
summarize.
Exam Tips
Remember for the exam
- A query starts with a table and pipes rows through operators.
- summarize with bin(TimeGenerated, interval) creates time series.
- AzureActivity answers who changed or deleted a resource.
- Heartbeat shows whether machines are reporting.