Welcome to the KQL Hit Doc – your all-in-one, charming, exhaustive, and battle-ready knowledge base on Kusto Query Language (KQL). This document is crafted as both a learning journal and an advanced cheat sheet to empower you with everything from beginner syntax to advanced analytics. Ideal for Azure Monitor, Application Insights, Log Analytics, and more.
- Introduction to KQL
- Core Concepts
- Basic Syntax
- Query Operators
- Data Types
- Data Ingestion and Schema
- Commonly Used Tables (Azure)
- Filtering, Sorting, Projection
- Aggregation & Summarization
- Joins and Lookups
- Subqueries and Let Statements
- Time Series Analysis
- Rendering & Visualization
- Advanced Functions & Plugins
- Security and Access Control
- Performance Tuning
- Tips, Tricks, and Patterns
- Real-life Scenarios and Examples
- Further Reading & References
Kusto Query Language (KQL) is a read-only query language designed for big data analytics. Used primarily in Azure Monitor, Log Analytics, and Application Insights, it is optimized for interactive ad hoc queries.
- Developed by Microsoft for Azure Data Explorer.
- Declarative and SQL-like but tailored for telemetry data.
- Use-cases: performance monitoring, diagnostics, security analysis.
- Everything is table-based.
- Queries are pipeline-based, flowing through
|operators. - Supports structured, semi-structured, and time-series data.
- Read-only: No data updates via KQL.
TableName
| where Condition
| summarize Count = count() by Column
| order by Count desc- Case-sensitive.
- Whitespace and indentation improve readability but are not required.
project,extend,summarize,where,order by,take,join- Control flow:
if,case - Type casting:
tostring(),toint(), etc.
- Primitive:
string,int,long,datetime,bool,real,guid - Complex:
dynamic(JSON-like),timespan
- In Azure, data is pushed into tables like
Perf,Heartbeat,SecurityEvent, etc. - Schema = columns + data types + metadata
Use .show and .ingest commands (in ADX context).
AzureActivity,SigninLogs,SecurityEventPerf,Syslog,Heartbeat,AppRequestsUsage,InsightsMetrics
SecurityEvent
| where EventID == 4625
| project TimeGenerated, Computer, Account
| order by TimeGenerated descSigninLogs
| summarize Failures = count() by bin(TimeGenerated, 1h), ResultTypecount(),avg(),max(),sum(),percentiles(),make_list()
Table1
| join kind=inner (Table2) on CommonColumninner,leftouter,rightouter,fullouter,anti,semi
let FailedLogins = SigninLogs | where ResultType != 0;
FailedLogins | summarize count() by UserPrincipalName- Use
letfor modular, reusable logic.
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| summarize avg(CounterValue) by bin(TimeGenerated, 5m)- Use
make-series,range,bin(), andserialize
Perf
| summarize avg(CounterValue) by bin(TimeGenerated, 5m)
| render timechart- Types:
timechart,barchart,piechart,table
- Math/Stats:
percentile(),variance(),stdev() - String:
split(),substring(),replace_string() - Datetime:
ago(),now(),startofhour() - Dynamic:
parse_json(),extractjson() - Plugins:
predict,anomaly_detection,cluster()
- RBAC at Azure Resource and Log Analytics Workspace level.
- Table-level permissions.
- KQL itself doesn’t write data, ensuring read-only integrity.
- Use
projectearly to limit columns. - Filter early (
where) to reduce row count. - Avoid wildcard searches (
contains→has/startswith) - Index-aware queries improve performance.
- Prefer
hasovercontainsfor word-matching. - Use
toscalar()to assign values from a query. - Use
distinctfor unique rows. - Combine logs with
union. - Debug using
print.
- Find top 5 IPs with failed login attempts:
SigninLogs
| where ResultType != 0
| summarize Count = count() by IPAddress
| top 5 by Count desc- Analyze CPU over time:
Perf
| where CounterName == "% Processor Time"
| summarize avg(CounterValue) by bin(TimeGenerated, 10m), Computer
| render timechart"Querying logs should be poetic."
KQL is not just a query language; it's an analyst's wand, a developer's magnifier, and a security guardian's shield. Use it to slice time, stitch patterns, sniff anomalies, and trace problems — all with readable, powerful syntax.
My Achievements:
Happy querying! ⚡
📁 Pro Tip: Use this
README.mdas your reference card, knowledge base, and personal guide while mastering KQL.