Configuring Log Analytics Workspaces

Watch the video to deepen your understanding.
SubscribeComplete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Configuring Log Analytics Workspaces
Introduction: The Central Hub for Azure Monitoring
In the dynamic world of cloud computing, robust logging and monitoring are not just good practices—they are necessities for maintaining performance, security, and operational efficiency. Azure Monitor provides a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments. At the heart of Azure Monitor's logging capabilities lies the Log Analytics Workspace.
A Log Analytics Workspace (LAW) acts as a unique data repository where log data from various sources in Azure and beyond is collected, aggregated, and stored. Think of it as the central brain that receives and processes all your operational intelligence. Without a properly configured LAW, you cannot effectively leverage the power of Azure Monitor for deep insights, proactive alerting, and historical analysis.
Why is it essential?
- Centralized Data Collection: Gathers logs from Azure resources, virtual machines, containers, network devices, and custom applications into a single, queryable location.
- Powerful Analytics: Enables deep analysis of log data using the Kusto Query Language (KQL), allowing you to identify trends, diagnose issues, and uncover security threats.
- Proactive Alerting: Powers Azure Monitor alerts, notifying you of critical events or performance thresholds being crossed.
- Visualization and Reporting: Serves as the data source for Azure Dashboards and Workbooks, providing visual insights into your environment.
- Compliance and Auditing: Retains logs for specified periods, helping meet compliance requirements and facilitating security audits.
Understanding Log Analytics Workspaces
Before diving into configuration, let's understand the core components and key properties of a Log Analytics Workspace.
Core Components and Purpose
A LAW is more than just storage; it's an analytical engine. When data is ingested, it's parsed, indexed, and stored in tables, making it highly efficient for complex queries. Each workspace is isolated, meaning data from one workspace cannot be directly queried from another, though cross-workspace queries are possible with specific permissions.
Key Properties
When designing and configuring your Log Analytics Workspace, several properties are crucial for performance, cost, and compliance:
SKU (Pricing Tier): The SKU determines the pricing model for your workspace. Common SKUs include:
- Pay-as-you-go: Standard pricing based on data ingestion and retention.
- Commitment Tiers: Offer discounted prices for committing to a certain level of data ingestion per day. Ideal for predictable, high-volume environments.
- Free: Limited to 500 MB of data ingestion per day with 7-day retention. Primarily for evaluation.
- Deprecated Tiers: Some older tiers like
Standard,Premium,Per GB2018might still exist but new workspaces should use current tiers.
Impact: Directly affects your monthly Azure bill. Choosing the right SKU based on your expected data volume is critical for cost optimization.
Data Retention: This setting defines how long ingested data is kept in the workspace.
- You can configure retention from 30 days up to 730 days (2 years) or even longer for specific tables.
- Longer retention periods incur higher costs.
- Some data types (e.g.,
AzureActivity) have a default 90-day retention at no extra charge, which is independent of the workspace's overall retention setting.
Impact: Crucial for compliance requirements (e.g., GDPR, HIPAA) and for historical analysis.
Daily Data Cap: An optional, but highly recommended, setting that allows you to specify a maximum amount of data (in GB) that can be ingested into your workspace per day.
- Once the cap is reached, data ingestion stops for the remainder of the day and resumes the next day.
- This prevents unexpected cost spikes due to misconfigured resources or malicious attacks generating excessive logs.
Impact: A vital cost control mechanism.
Region: The Azure region where your Log Analytics Workspace is deployed.
- It's generally recommended to deploy your workspace in the same region as the majority of the resources sending data to it to minimize latency and potential data transfer costs.
Impact: Affects latency, data sovereignty, and potentially data egress costs if data is sent across regions.
Creating a Log Analytics Workspace
You can create a Log Analytics Workspace using the Azure Portal, Azure CLI, or ARM Templates for automation.
Azure Portal (Brief Overview)
- Navigate to the Azure Portal.
- Search for "Log Analytics workspaces" and click "Create".
- Fill in basic details: Subscription, Resource Group, Name, Region, and Pricing Tier.
- Click "Review + create", then "Create".
Azure CLI (Code Snippet)
Using Azure CLI is a common way to automate resource deployment.
# Define variables
RESOURCE_GROUP_NAME="my-monitoring-rg"
WORKSPACE_NAME="my-law-prod-eastus"
LOCATION="eastus"
SKU="PerGB2018" # Or "Consumption" for newer tiers, or a Commitment Tier like "100GB_Commitment"
RETENTION_DAYS=90 # 30 to 730 days
# Create a resource group if it doesn't exist
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
# Create the Log Analytics Workspace
az monitor log-analytics workspace create \
--resource-group $RESOURCE_GROUP_NAME \
--workspace-name $WORKSPACE_NAME \
--location $LOCATION \
--sku $SKU \
--retention-time $RETENTION_DAYS
# Optionally set a daily data cap (e.g., 50 GB)
az monitor log-analytics workspace update \
--resource-group $RESOURCE_GROUP_NAME \
--workspace-name $WORKSPACE_NAME \
--daily-quota-gb 50
ARM Template (Code Snippet)
For infrastructure as code (IaC), ARM templates are ideal.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string",
"defaultValue": "my-law-prod-westus",
"metadata": {
"description": "Name of the Log Analytics workspace."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Log Analytics workspace."
}
},
"sku": {
"type": "string",
"defaultValue": "PerGB2018",
"allowedValues": [
"Free",
"PerGB2018",
"Consumption",
"100GB_Commitment",
"200GB_Commitment",
"300GB_Commitment",
"400GB_Commitment",
"500GB_Commitment",
"1000GB_Commitment",
"2000GB_Commitment",
"5000GB_Commitment"
],
"metadata": {
"description": "Pricing tier for the Log Analytics workspace."
}
},
"retentionInDays": {
"type": "int",
"defaultValue": 90,
"minValue": 30,
"maxValue": 730,
"metadata": {
"description": "Number of days to retain data."
}
},
"dailyQuotaGb": {
"type": "int",
"defaultValue": 50,
"metadata": {
"description": "Daily data ingestion cap in GB."
}
}
},
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2022-10-01",
"name": "[parameters('workspaceName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "[parameters('sku')]"
},
"retentionInDays": "[parameters('retentionInDays')]",
"workspaceCapping": {
"dailyQuotaGb": "[parameters('dailyQuotaGb')]"
}
}
}
]
}
Connecting Data Sources
Once your workspace is created, the next step is to populate it with data.
Azure Resources (Diagnostic Settings)
Most Azure services (e.g., App Services, Key Vaults, Network Security Groups, Storage Accounts) can send their diagnostic logs and metrics directly to a Log Analytics Workspace via Diagnostic Settings.
- Navigate to an Azure resource (e.g., an Azure Function App).
- In the left-hand menu, under "Monitoring," select "Diagnostic settings."
- Click "Add diagnostic setting."
- Give it a name.
- Under "Destination details," select "Send to Log Analytics workspace."
- Choose your Subscription and the target Log Analytics Workspace.
- Select the log categories and metrics you want to send.
- Click "Save."
Azure Virtual Machines (Azure Monitor Agent)
For Azure VMs, on-premises servers, and other cloud VMs, the Azure Monitor Agent (AMA) is the primary method for collecting guest-level telemetry. This agent replaces the legacy Log Analytics agent (MMA).
- Navigate to your Log Analytics Workspace.
- Under "Settings," select "Agents and virtual machines."
- Follow the instructions to deploy the Azure Monitor Agent to your VMs. This typically involves creating a Data Collection Rule (DCR) that specifies what data to collect and where to send it (your LAW).
- You can also deploy AMA via Azure Policy, ARM templates, or the Azure Portal's VM blade.
Custom Logs (Brief Mention)
For applications generating custom log files or using specific logging frameworks, you can configure custom log collection or use data ingest APIs to send data directly to your workspace.
Querying Data with Kusto Query Language (KQL)
KQL is a powerful query language used to interact with data in Log Analytics Workspaces. It's designed for efficiency and flexibility.
Basic KQL Syntax
A KQL query typically starts with a table name, followed by operators separated by pipes (|).
TableName | operator1 | operator2 | ...
Practical KQL Examples
Let's explore some common queries:
1. View VM Heartbeat logs:
The Heartbeat table indicates if the Azure Monitor Agent is successfully communicating.
Heartbeat
| where OSType == "Windows" // Filter for Windows VMs
| summarize LastHeartbeat = max(TimeGenerated) by Computer // Get the last heartbeat for each computer
| extend TimeSinceLastHeartbeat = now() - LastHeartbeat // Calculate time since last heartbeat
| where TimeSinceLastHeartbeat > 5m // Find VMs with no heartbeat in the last 5 minutes
2. Analyze Azure Activity Logs:
The AzureActivity table contains logs from Azure subscriptions, providing insights into control-plane operations.
AzureActivity
| where TimeGenerated > ago(1h) // Logs from the last hour
| where ActivityStatus == "Failed" // Find failed operations
| project TimeGenerated, OperationName, ResourceGroup, Caller, CorrelationId // Select relevant columns
| sort by TimeGenerated desc
3. Monitor VM Performance (CPU Usage):
The Perf table stores performance counters from VMs.
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time" // CPU usage
| summarize avg(CounterValue) by Computer, bin(TimeGenerated, 1h) // Average CPU per hour per computer
| render timechart // Visualize as a time chart
4. Query App Service Logs:
If you send App Service logs to LAW, they typically land in AppServiceLogs.
AppServiceLogs
| where LogLevel == "Error" // Filter for error logs
| project TimeGenerated, AppName, Message // Show time, app name, and error message
| sort by TimeGenerated desc
Access Control and Security
Securing your Log Analytics Workspace is paramount. Azure Role-Based Access Control (RBAC) is used to manage who can access and perform operations within your workspace.
- Workspace-level permissions: Grant roles like "Log Analytics Reader," "Log Analytics Contributor," or "Owner" to control access to the entire workspace.
- Table-level permissions: For
Reach the last section to complete this lesson and earn points — you're on section 1 of 5.
- Introduction to Azure Monitor
- Azure Monitor Architecture and Data Sources
- Configuring Log Analytics Workspaces
- Designing Log Routing Solutions
- Configuring Diagnostic Settings
- Application Insights for Solution Architects
- Network Watcher and Network Monitoring
- Azure Monitor Alerts and Action Groups
- Workbooks and Custom Dashboards
- Designing a Comprehensive Monitoring Strategy
- Logging and Monitoring Quiz5q
- Microsoft Entra ID for Solution Architects
- Designing Identity Solutions: B2B Collaboration
- Designing Identity Solutions: B2C Scenarios
- Conditional Access Policy Design
- Designing for Multi-Factor Authentication
- Managed Identities for Azure Resources
- Service Principals and App Registrations
- Role-Based Access Control Design
- Privileged Identity Management
- Microsoft Entra ID Protection
- Zero Trust Architecture with Microsoft Entra
- Authentication and Authorization Quiz5q
- Introduction to Azure Governance
- Designing Management Group Hierarchies
- Subscription Strategy Design
- Resource Group Organization Patterns
- Azure Policy Design and Assignment
- Custom Policy Definitions and Initiatives
- Resource Locks and Tagging Strategies
- Azure Blueprints and Landing Zones
- Cost Management and Budget Design
- Cloud Adoption Framework for Governance
- Governance Solutions Quiz5q
- Introduction to Azure Storage
- Storage Account Types and Replication
- Blob Storage Tiers and Lifecycle Management
- Azure Files and Azure NetApp Files
- Azure Managed Disks Design
- Azure Data Lake Storage Gen2
- Cosmos DB Consistency Models
- Cosmos DB Partitioning and Throughput Design
- Cosmos DB API Selection Guide
- Table Storage and Queue Storage Design
- Storage Security and Encryption
- Non-Relational Storage Quiz5q
- Azure SQL Database Service Tiers
- Azure SQL Managed Instance Design
- Azure Database for MySQL and PostgreSQL
- Database Scaling: Vertical and Horizontal
- Read Replicas and Geo-Replication
- Database Security and Auditing Design
- Transparent Data Encryption and Always Encrypted
- Caching with Azure Cache for Redis
- Azure SQL Elastic Pools Design
- Relational Storage Quiz5q
- Azure Data Factory Design Patterns
- Data Integration Pipeline Architecture
- Azure Synapse Analytics Design
- Azure Databricks Integration Patterns
- Azure Stream Analytics for Real-Time Data
- Azure Event Hubs for Data Ingestion
- Data Migration Strategies and Tools
- Azure Purview for Data Governance
- Data Integration Quiz5q
- Introduction to High Availability in Azure
- Availability Zones and Availability Sets
- Azure Load Balancer Design
- Application Gateway and WAF Design
- Azure Front Door and Global Load Balancing
- Azure Traffic Manager Routing Methods
- Multi-Region Architecture Design
- SLA Design and Composite SLAs
- Health Probes and Failover Configuration
- Azure Service Fabric for Stateful HA
- High Availability Quiz5q
- Azure Backup Architecture and Vaults
- Backup Policies for VMs and Databases
- Azure Site Recovery Design
- RTO and RPO Planning Strategies
- Geo-Redundant and Cross-Region Recovery
- Hybrid and On-Premises Backup Solutions
- Resiliency Patterns and Chaos Engineering
- Disaster Recovery Testing and Drills
- Azure Immutable Backup and Soft Delete
- Backup and Disaster Recovery Quiz5q
- Introduction to Azure Compute Options
- Virtual Machine Design and Sizing
- VM Scale Sets and Autoscaling Strategies
- Azure Batch for Large-Scale Workloads
- Azure App Service Plans and Design
- App Service Environments and Isolation
- Azure Container Instances
- Azure Kubernetes Service Architecture
- AKS Networking and Storage Design
- Azure Functions and Serverless Design
- Durable Functions and Orchestration
- Compute Decision Framework
- Azure Virtual Desktop Design
- Compute Solutions Quiz5q
- Microservices Architecture Patterns
- Azure API Management Design
- Azure Service Bus Messaging Design
- Azure Event Grid and Event-Driven Architecture
- Azure Event Hubs for Streaming
- Azure Logic Apps and Integration Workflows
- Azure SignalR and Web PubSub
- Caching Strategies and Azure CDN
- App Configuration and Feature Flags
- Designing for Scalability and Performance
- Azure Container Apps Design
- Application Architecture Quiz5q
- Virtual Network Design and Address Planning
- Subnet Design and Network Segmentation
- Hub-Spoke Network Topology
- Azure Virtual WAN Design
- VPN Gateway Design and Configuration
- ExpressRoute Circuit Design
- Network Security Groups Design
- Azure Firewall and Firewall Manager
- Azure DDoS Protection Design
- Private Endpoints and Private Link
- Azure DNS and DNS Architecture
- Network Performance and Traffic Routing
- Azure Bastion and Secure Access
- Network Solutions Quiz5q
- Azure Migrate Overview and Assessment
- Migration Assessment and Discovery
- Azure Cloud Adoption Framework for Migration
- VM Migration with Azure Migrate
- Database Migration with Azure DMS
- Application Migration to App Service
- Containerizing Applications for Migration
- Migration Cost Planning and Optimization
- Data Box and Offline Migration Methods
- Migrations Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons