| Azure-Insights | Azure-Log-Analytics | |
Kusto Query Language (KQL) Overview |
Kusto Query Language (KQL) is a powerful, read-only query language used to explore, analyze, and visualize large volumes of structured, semi-structured, and unstructured data in Azure services such as Log Analytics, Application Insights, and Azure Data Explorer.
Logs | where TimeGenerated > ago(1h) | where SeverityLevel == "Error" | summarize ErrorCount = count() by Computer | order by ErrorCount desc
Kusto Query Language (KQL) is a read-only, data exploration language used across Azure services like:
Itβs designed for fast, interactive analysis of large datasets β especially telemetry, logs, metrics, and time-series data β without modifying the underlying data.
| Concept | Description |
|---|---|
| Read-only | You can query and transform data, but not insert/update/delete. |
| Data-flow model | Queries are built as a sequence of operations connected by a pipe (|) β each step transforms the table before passing it on. |
| Schema hierarchy | Data is organized into databases β tables β columns (similar to SQL). |
| Case-sensitive | Table names, column names, and operators are case-sensitive. |
| Optimized for telemetry | Rich support for text search, parsing, time-series, aggregation, and anomaly detection. |
TableName | where Timestamp > ago(1h) | project ColumnA, ColumnB | summarize Count = count() by ColumnA | order by Count desc
How it works:
where)project)summarize)order by)| Operator | Purpose | Example |
|---|---|---|
| where | Filter rows | where Level == "Error" |
| project | Select columns | project TimeGenerated, Message |
| summarize | Aggregate | summarize avg(DurationMs) by UserId |
| extend | Add calculated columns | extend LoadTimeSec = DurationMs / 1000 |
| join | Combine tables | join kind=inner |
| order by | Sort results | order by Count desc |
| parse | Extract values from text | parse Message with "User:" UserId " logged in" |
Scenario: Find the top 5 IP addresses with the most failed logins in the last 24 hours.
SigninLogs | where ResultType != 0 | where TimeGenerated > ago(24h) | summarize Failures = count() by IPAddress | top 5 by Failures desc
where as soon as possible to reduce dataset size.summarize wisely β Aggregate before joins to reduce cost.TenantId to filter dashboards per tenant.20+ ready-to-use query patterns for Azure Monitor, Microsoft Sentinel, and Application Insights.
Heartbeat
| summarize Count = count() by Computer
List all monitored computers with heartbeat count.
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| summarize AvgCPU = avg(CounterValue) by bin(TimeGenerated, 5m), Computer
Average CPU usage per computer in 5-min bins.
AzureActivity
| where ActivityStatus == "Failed"
| project TimeGenerated, Caller, OperationName, ActivityStatus
Show failed Azure operations.
SecurityEvent
| where EventID == 4625
| summarize FailedLogins = count() by Account, bin(TimeGenerated, 1h)
Failed login attempts per account per hour.
InsightsMetrics
| where Name == "Requests"
| summarize TotalRequests = sum(Val) by bin(TimeGenerated, 1h), Resource
Total requests per resource per hour.
SigninLogs
| where ResultType != 0
| summarize Failures = count() by UserPrincipalName, IPAddress
Failed sign-ins by user and IP.
SecurityAlert
| summarize Alerts = count() by AlertName, Severity
Count of alerts by name and severity.
SecurityIncident
| where Status == "Active"
| project IncidentNumber, Title, Severity, Owner
List active incidents with details.
OfficeActivity
| where Operation == "FileAccessed"
| summarize AccessCount = count() by UserId, Site_Url
File access count by user and site.
DeviceNetworkEvents
| where RemoteUrl contains "malicious.com"
| project Timestamp, DeviceName, RemoteUrl
Detect connections to malicious domains.
requests
| summarize AvgDuration = avg(duration) by bin(timestamp, 1h)
Average request duration per hour.
requests
| where success == "False"
| summarize Failures = count() by name
Failed requests by operation name.
dependencies
| summarize AvgDuration = avg(duration) by target
Average dependency call duration by target.
traces
| where message contains "Exception"
| project timestamp, message, severityLevel
List exception traces with severity.
pageViews
| summarize Views = count() by name
Page view count by page name.
union requests, dependencies
| summarize TotalCalls = count() by bin(timestamp, 1h)
Combine requests and dependencies for total calls per hour.
SigninLogs
| join kind=inner (SecurityAlert) on $left.UserPrincipalName == $right.CompromisedEntity
| project TimeGenerated, UserPrincipalName, AlertName
Correlate sign-ins with security alerts.
Perf
| where CounterName == "% Processor Time"
| summarize AvgCPU = avg(CounterValue) by Computer
| order by AvgCPU desc
Top CPU-consuming machines.
SecurityEvent
| where EventID in (4720, 4722, 4723)
| summarize Count = count() by EventID, Account
Track account creation, enable, and password change events.
requests
| extend DurationSec = todouble(duration)/1000
| summarize P95 = percentile(DurationSec, 95) by bin(timestamp, 1h)
95th percentile request duration per hour.
Heartbeat
| summarize LastSeen = max(TimeGenerated) by Computer
| where LastSeen < ago(1h)
Machines not reporting heartbeat in the last hour.
where to reduce dataset size.project to select only needed columns.summarize before joins for performance. | Azure-Insights | Azure-Log-Analytics | |