Configuring Data Collection Rules
Complete 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
Mastering Data Collection Rules (DCRs) in Azure
Introduction: The Foundation of Modern Security Monitoring
In the landscape of cloud security, the quality of your security monitoring is strictly limited by the quality of the data you collect. If you are not collecting the right logs at the right time, your security tools—no matter how advanced—cannot protect your environment. This is where Data Collection Rules (DCRs) come into play. DCRs represent the modern standard for how Azure resources, virtual machines, and hybrid workloads send telemetry data to Azure Monitor and Microsoft Sentinel.
Historically, collecting logs in Azure was a fragmented process involving legacy agents, complex workspace settings, and broad, "all-or-nothing" collection policies. DCRs change this paradigm by offering granular control over what data is collected, where it is sent, and how it is processed before it lands in your storage tables. For security engineers, understanding DCRs is the difference between having a manageable, cost-effective security operation and drowning in a sea of irrelevant, expensive noise.
This lesson explores the mechanics of DCRs, the transition from legacy collection methods, and the practical implementation strategies you need to build a high-fidelity monitoring environment. Whether you are managing a handful of virtual machines or a massive enterprise footprint, mastering DCRs is essential for ensuring your security operations center (SOC) has the visibility required to detect and respond to threats effectively.
The Evolution of Data Collection: Why DCRs Matter
To understand the importance of DCRs, we must look at the "Before" state. Previously, we relied heavily on the Log Analytics agent (the "MMA" or Microsoft Monitoring Agent) and the Azure Diagnostic extension. These tools often forced administrators to enable entire categories of logs, such as "All Security Events" or "All Syslog," which frequently led to massive ingestion costs and storage bloat.
DCRs introduce a declarative approach to data ingestion. Instead of configuring settings on every single server, you define a rule that describes:
- The Source: Which machines or resources are sending the data.
- The Data Stream: What specific logs or performance counters are needed (e.g., Security Events, Syslog, custom JSON logs).
- The Transformation: What logic should be applied to the data before it is ingested (e.g., filtering out low-value events).
- The Destination: Where the data should land, such as a specific Log Analytics Workspace or an Event Hub.
By moving to this model, you gain the ability to filter logs at the source. If your security team only needs to track failed login attempts and specific process creation events, you can configure your DCR to discard everything else before it ever leaves the virtual machine. This reduces network egress costs, minimizes storage requirements, and makes your security queries run much faster because they aren't scanning through millions of unnecessary lines of data.
Callout: DCRs vs. Legacy Agents The transition from the legacy Log Analytics agent to the Azure Monitor Agent (AMA) is powered entirely by DCRs. While the legacy agent was a "monolithic" configuration, the AMA is modular. DCRs allow you to associate specific configurations with specific subsets of machines, enabling a "least privilege" approach to log collection. This modularity ensures that you are only paying for and storing the data that actually contributes to your security posture.
Architecture of a Data Collection Rule
A Data Collection Rule is an Azure Resource Manager (ARM) object. It is defined using JSON, which makes it highly portable and suitable for Infrastructure-as-Code (IaC) workflows. When you create a DCR, you are essentially creating a blueprint for the Azure Monitor Agent (AMA) that resides on your virtual machines.
Key Components of a DCR
- Data Sources: This section defines the input. It specifies the type of data, such as Windows Event Logs, Linux Syslog, or performance counters. You can define multiple sources within a single rule.
- Data Flows: This section maps the input sources to a specific destination. You can send data to one or multiple Log Analytics Workspaces.
- Transformations: This is perhaps the most powerful feature. Transformations allow you to use Kusto Query Language (KQL) to drop rows, rename columns, or modify data fields at the point of ingestion.
Example: A Basic DCR Structure
{
"location": "eastus",
"properties": {
"dataSources": {
"windowsEventLogs": [
{
"name": "securityEventSource",
"streams": ["Microsoft-SecurityEvent"],
"xPathQueries": ["Security!*[System[(EventID=4624 or EventID=4625)]]"]
}
]
},
"destinations": {
"logAnalytics": [
{
"workspaceResourceId": "/subscriptions/.../workspaces/my-workspace",
"name": "central-workspace"
}
]
},
"dataFlows": [
{
"streams": ["Microsoft-SecurityEvent"],
"destinations": ["central-workspace"]
}
]
}
}
In the example above, the DCR is configured specifically to collect only Event IDs 4624 (successful login) and 4625 (failed login) from the Windows Security log. This is a massive improvement over traditional methods that would have required collecting the entire Security log and filtering it later within Sentinel.
Step-by-Step: Configuring Data Collection Rules
To implement DCRs effectively, follow this structured approach. We will focus on deploying a rule for a Windows Virtual Machine.
Step 1: Install the Azure Monitor Agent (AMA)
Before a DCR can function, the AMA must be installed on your target machine. You can do this via the Azure Portal, or more efficiently, using Azure Policy to enforce the installation across all machines in a subscription.
- Navigate to Monitor > Data Collection Rules.
- Click Create.
- Provide a name and select your Subscription and Resource Group.
- In the Resources tab, add the virtual machines you want to monitor. Ensure they have the AMA extension installed (the portal will prompt you to install it if missing).
Step 2: Define Data Sources
After selecting your resources, you must tell the agent what to collect.
- Click Add data source.
- Choose the data source type (e.g., Windows Event Logs).
- Select the log level (Critical, Error, Warning, Information).
- Use the Custom option to enter specific XPath queries if you want to be highly selective.
Step 3: Configure Destination
- Select the Destination tab.
- Choose your Log Analytics Workspace.
- Click Review + create.
Note: When you associate a DCR with a virtual machine, the agent on the machine pulls the configuration within a few minutes. If you make changes to the DCR later, the agent will automatically update its configuration, typically within 5-10 minutes.
Advanced Feature: Data Transformations
Transformations allow you to modify logs before they are written to the workspace. This is critical for security compliance, such as removing sensitive information (like PII) from logs or cleaning up noisy, high-volume telemetry that isn't useful for security alerts.
Practical Example: Masking Sensitive Data
Imagine you have an application log that occasionally records internal IP addresses that you want to anonymize to comply with privacy policies. You can use a transformation to replace the IP string with a hashed value or a generic placeholder.
"transformKql": "source | extend IPAddress = 'REDACTED'"
This simple KQL statement is applied at the ingestion pipeline level. The original data never hits your storage, which saves you money and reduces your compliance footprint.
Warning: Be cautious when using transformations. If you accidentally write a KQL query that causes an error or filters out too much data, you may inadvertently create a "blind spot" in your security monitoring. Always test your transformation queries in a development workspace before applying them to production traffic.
Best Practices for Security Monitoring
Security monitoring is not a "set it and forget it" task. To maintain a robust environment, adhere to these industry-standard practices:
1. Adopt a "Least Privilege" Collection Strategy
Do not collect everything "just in case." Every gigabyte of data you ingest costs money and increases the processing time for security analysts. Start by identifying the specific threats you are trying to detect (e.g., brute force attacks, lateral movement, privilege escalation) and configure your DCRs to collect only the logs required to trigger those specific alerts.
2. Leverage Azure Policy for Governance
Do not manually assign DCRs to every virtual machine. As your environment scales, this becomes unmanageable. Instead, use Azure Policy to automatically associate a DCR with any new virtual machine that is deployed. This ensures that every server in your environment is "secure by default" from the moment it is created.
3. Use Custom Data Streams for Application Logs
If you have custom applications, don't force them into standard Syslog or Windows Event formats. Use the Data Collection API to send logs directly to a custom table in your Log Analytics Workspace. This allows you to define a specific schema that makes it easier to write high-performance Sentinel detection rules.
4. Monitor Your DCR Health
Azure provides metrics to track the health of your data collection. Monitor the "Data Collection Rule Errors" metric in Azure Monitor. If an agent fails to apply a rule or if there is a schema mismatch, you will see it here. Proactive monitoring prevents gaps in your security visibility.
5. Periodically Review Data Costs
Use the "Log Analytics Workspace Insights" feature to visualize which tables are consuming the most data. If you notice a specific DCR is collecting massive amounts of unnecessary noise, revisit the rule and refine your XPath queries or transformations to filter the data more aggressively.
Comparison: Legacy vs. Modern Collection
| Feature | Legacy Agent (MMA) | Azure Monitor Agent (AMA) |
|---|---|---|
| Configuration | Workspace-wide settings | Granular, per-machine DCRs |
| Performance | High resource overhead | Optimized for lower CPU/Memory |
| Filtering | Limited (mostly broad categories) | High (XPath and KQL transformations) |
| Scalability | Difficult to manage at scale | Managed via Azure Policy |
| Lifecycle | Being retired | Current standard |
Common Pitfalls and How to Avoid Them
Pitfall 1: Over-Collection (The "Data Swamp")
Many organizations try to ingest every single log file available. This creates a "data swamp" where meaningful security signals are buried under terabytes of useless information.
- The Fix: Start with a baseline of essential security logs (e.g., Authentication, Process Creation, PowerShell execution). Only add more logs if you have a specific use case (a detection rule or threat hunting query) that requires them.
Pitfall 2: Conflicting DCRs
You can assign multiple DCRs to a single virtual machine. If you aren't careful, you may accidentally create overlapping rules that cause the agent to collect the same data twice or cause configuration conflicts.
- The Fix: Create a clear naming convention for your DCRs and maintain a documentation matrix of which DCRs apply to which server roles (e.g., "Web-Server-DCR," "Domain-Controller-DCR").
Pitfall 3: Ignoring Transformation Errors
Transformations are powerful, but they can fail. If a transformation logic is broken, the log might be dropped entirely, leading to a silent failure where you think you are collecting data, but you are not.
- The Fix: Always test your KQL transformations in the Log Analytics interface using existing log data before applying them to a DCR. Use the
projectandextendoperators carefully to ensure the schema remains consistent.
Callout: The Importance of Schema Consistency When you use transformations, you are essentially changing the "shape" of the data. If you change a field name or data type, your existing Sentinel alerts might break because they are looking for the old schema. Always coordinate with your security analysts before changing the structure of logs via a DCR transformation.
Scaling Your Monitoring Strategy
As you move from a few servers to hundreds or thousands, the administrative burden of managing DCRs can grow. To manage this at scale, you should treat your DCRs as code. Store your JSON definitions in a Git repository and use CI/CD pipelines to deploy them to Azure.
Implementing Infrastructure as Code (IaC)
Using Bicep or Terraform to define your DCRs provides several advantages:
- Version Control: You can track who changed a collection rule and why.
- Auditability: You have a clear record of your monitoring policy.
- Consistency: You can ensure that the exact same monitoring configuration is applied across Dev, Test, and Production environments.
Example: Bicep Snippet for DCR
resource dataCollectionRule 'Microsoft.Insights/dataCollectionRules@2022-06-01' = {
name: 'security-audit-dcr'
location: 'eastus'
properties: {
dataSources: {
windowsEventLogs: [
{
name: 'audit-logs'
streams: [
'Microsoft-SecurityEvent'
]
xPathQueries: [
'Security!*[System[(EventID=4624)]]'
]
}
]
}
destinations: {
logAnalytics: [
{
workspaceResourceId: logAnalyticsWorkspaceId
name: 'sentinel-workspace'
}
]
}
}
}
By using Bicep, you can modularize your monitoring. You can create a "base" DCR module that includes standard security logs and then include additional modules for specific application-level logs as needed.
Troubleshooting Common DCR Issues
Even with careful planning, things can go wrong. Here are the steps to follow when you suspect data collection is failing:
- Verify Agent Status: Check the virtual machine "Extensions" blade in the Azure Portal. Ensure the
AzureMonitorWindowsAgentorAzureMonitorLinuxAgentis listed as "Provisioning succeeded." - Check Heartbeat: Query the
Heartbeattable in Log Analytics. If you see heartbeats from the machine, the agent is running and communicating with Azure. If you don't see heartbeats, the issue is with the agent or network connectivity (e.g., firewall blocking outbound traffic to Azure Monitor endpoints). - Validate DCR Association: Use the Azure CLI or PowerShell to list the DCR associations for your VM.
az monitor data-collection rule association list --resource <vm-id>- Ensure the expected DCR is present in the list.
- Examine Agent Logs: If the agent is running but not sending logs, check the local agent logs on the VM. On Windows, these are typically located in
C:\Packages\Plugins\Microsoft.Azure.Monitor.AzureMonitorWindowsAgent\...\Logs. These logs will often contain specific error messages regarding schema validation or connectivity.
Deep Dive: The Role of Sentinel and DCRs
While DCRs are technically an Azure Monitor feature, they are the lifeblood of Microsoft Sentinel. Sentinel is a SIEM (Security Information and Event Management) system, and it relies on the data ingested via these rules to run its analytics.
When you configure a DCR to send data to a workspace, that data becomes available to Sentinel. You can then use Sentinel’s "Data Connectors" to enable specific security content (like workbooks and analytic rules) that are tailored to that data source. For example, if your DCR collects Windows Security events, you can enable the "Windows Security Events" connector in Sentinel, which automatically installs dozens of pre-built detection rules that look for suspicious behavior like pass-the-hash attacks or clearing of security logs.
The synergy between DCRs and Sentinel allows you to move from raw data ingestion to actionable security intelligence. By carefully crafting your DCRs, you ensure that the Sentinel detection rules have the high-fidelity data they need to fire accurately, which reduces false positives and helps your SOC team focus on real threats.
Final Best Practices Summary
- Standardize: Create a core set of DCRs that apply to all virtual machines (e.g., Heartbeat, basic Security events) and keep them in a centralized repository.
- Filter Early: Use XPath queries and KQL transformations to drop noise at the source. Do not ingest data you don't need.
- Automate: Use Azure Policy to associate DCRs with resources automatically. Manual association is prone to human error and leads to inconsistent security coverage.
- Validate: Periodically test your detection rules against the data you are collecting to ensure the data is complete. A detection rule is only as good as the logs it analyzes.
- Document: Keep track of why specific logs are collected. If a teammate asks why a certain log is present, you should be able to point to a specific security requirement or compliance mandate.
Key Takeaways
- DCRs are the Modern Standard: Data Collection Rules (DCRs) replace legacy agents, providing a scalable, declarative way to manage how telemetry is collected from Azure resources.
- Granularity is Key: Unlike legacy methods, DCRs allow for precise control over data collection. Use XPath queries to collect only the specific events you need, reducing costs and storage overhead.
- Transformations for Efficiency: Leverage KQL-based transformations at the ingestion level to mask sensitive data, clean up logs, or remove unnecessary fields before they enter your workspace.
- Governance via Policy: Use Azure Policy to enforce DCR association, ensuring that all virtual machines in your environment are monitored according to your organization’s security standards.
- Infrastructure as Code: Treat your DCRs as code by using Bicep or Terraform. This ensures your monitoring configuration is version-controlled, auditable, and consistent across environments.
- Sentinel Integration: DCRs are the foundation of your Microsoft Sentinel environment. High-quality, filtered data from DCRs results in more accurate detection rules and a more effective SOC.
- Proactive Health Monitoring: Don't assume collection is working indefinitely. Monitor your agent health, verify DCR associations, and review data ingestion costs regularly to maintain a healthy and cost-effective monitoring posture.
By mastering Data Collection Rules, you are not just configuring logs; you are building the visibility layer for your entire security operation. Take the time to design your rules carefully, automate their deployment, and refine them as your security needs evolve. This disciplined approach will pay dividends in both the effectiveness of your threat detection and the efficiency of your cloud security spend.
Reach the last section to complete this lesson and earn points — you're on section 1 of 11.
- Understanding Azure Built-in Role Assignments
- Understanding Azure Built-in Role Assignments5q
- Managing Custom Azure Roles
- Managing Custom Azure Roles5q
- Creating Custom Microsoft Entra Roles
- Creating Custom Microsoft Entra Roles5q
- Planning Privileged Identity Management
- Planning Privileged Identity Management5q
- Configuring PIM Settings and Assignments
- Configuring PIM Settings and Assignments5q
- Implementing Multi-Factor Authentication
- Implementing Multi-Factor Authentication5q
- Implementing Conditional Access Policies
- Implementing Conditional Access Policies5q
- Advanced Conditional Access Scenarios
- Advanced Conditional Access Scenarios5q
- Managing Enterprise Application Access
- Managing Enterprise Application Access5q
- Managing OAuth Permission Grants
- Managing OAuth Permission Grants5q
- Configuring App Registration Permission Scopes
- Configuring App Registration Permission Scopes5q
- Managing Service Principals
- Managing Service Principals5q
- Managing Managed Identities
- Managing Managed Identities5q
- Planning and Implementing NSGs
- Planning and Implementing NSGs5q
- Implementing Application Security Groups
- Implementing Application Security Groups5q
- Managing VNets with Virtual Network Manager
- Managing VNets with Virtual Network Manager5q
- Implementing User-Defined Routes
- Implementing User-Defined Routes5q
- Configuring VNet Peering and VPN Gateway
- Configuring VNet Peering and VPN Gateway5q
- Implementing Virtual WAN and Secured Hub
- Implementing Virtual WAN and Secured Hub5q
- Securing VPN and ExpressRoute Connectivity
- Securing VPN and ExpressRoute Connectivity5q
- Monitoring with Network Watcher
- Monitoring with Network Watcher5q
- Implementing Service Endpoints
- Implementing Service Endpoints5q
- Implementing Private Endpoints
- Implementing Private Endpoints5q
- Implementing Private Link Services
- Implementing Private Link Services5q
- Network Integration for App Service and Functions
- Network Integration for App Service and Functions5q
- Network Security for ASE and SQL Managed Instance
- Network Security for ASE and SQL Managed Instance5q
- Implementing TLS for Applications
- Implementing TLS for Applications5q
- Planning and Implementing Azure Firewall
- Planning and Implementing Azure Firewall5q
- Managing Firewall Policies with Azure Firewall Manager
- Managing Firewall Policies with Azure Firewall Manager5q
- Implementing Azure Application Gateway
- Implementing Azure Application Gateway5q
- Implementing Azure Front Door and CDN
- Implementing Azure Front Door and CDN5q
- Implementing Web Application Firewall
- Implementing Web Application Firewall5q
- Implementing Azure DDoS Protection
- Implementing Azure DDoS Protection5q
- Remote Access with Azure Bastion
- Remote Access with Azure Bastion5q
- Implementing Just-in-Time VM Access
- Implementing Just-in-Time VM Access5q
- Configuring AKS Network Isolation
- Configuring AKS Network Isolation5q
- Securing and Monitoring AKS
- Securing and Monitoring AKS5q
- AKS Authentication Configuration
- AKS Authentication Configuration5q
- Security Monitoring for Container Instances and Apps
- Security Monitoring for Container Instances and Apps5q
- Managing Access to Azure Container Registry
- Managing Access to Azure Container Registry5q
- Configuring Disk Encryption Options
- Configuring Disk Encryption Options5q
- Security for Azure API Management
- Security for Azure API Management5q
- Configuring Storage Account Access Control
- Configuring Storage Account Access Control5q
- Managing Storage Account Access Keys
- Managing Storage Account Access Keys5q
- Configuring Access to Azure Files
- Configuring Access to Azure Files5q
- Configuring Access to Azure Blob Storage
- Configuring Access to Azure Blob Storage5q
- Data Protection with Soft Delete and Versioning
- Data Protection with Soft Delete and Versioning5q
- Configuring BYOK and Infrastructure Encryption
- Configuring BYOK and Infrastructure Encryption5q
- Enabling Microsoft Entra Database Authentication
- Enabling Microsoft Entra Database Authentication5q
- Enabling Database Auditing
- Enabling Database Auditing5q
- Implementing Dynamic Data Masking
- Implementing Dynamic Data Masking5q
- Implementing Transparent Data Encryption
- Implementing Transparent Data Encryption5q
- Using Azure SQL Always Encrypted
- Using Azure SQL Always Encrypted5q
- Creating and Assigning Azure Policies
- Creating and Assigning Azure Policies5q
- Interpreting Azure Policy Initiatives
- Interpreting Azure Policy Initiatives5q
- Configuring Key Vault Network Settings
- Configuring Key Vault Network Settings5q
- Configuring Key Vault Access Policies and RBAC
- Configuring Key Vault Access Policies and RBAC5q
- Managing Certificates Secrets and Keys
- Managing Certificates Secrets and Keys5q
- Configuring Key Rotation and Backup
- Configuring Key Rotation and Backup5q
- Implementing Backup Security Controls
- Implementing Backup Security Controls5q
- Using Secure Score and Inventory
- Using Secure Score and Inventory5q
- Managing Compliance Standards
- Managing Compliance Standards5q
- Adding Custom Standards to Defender
- Adding Custom Standards to Defender5q
- Connecting Multi-Cloud Environments
- Connecting Multi-Cloud Environments5q
- Using External Attack Surface Management
- Using External Attack Surface Management5q
- Enabling Cloud Workload Protection Plans
- Enabling Cloud Workload Protection Plans5q
- Configuring Defender for Servers
- Configuring Defender for Servers5q
- Configuring Defender for Databases and Storage
- Configuring Defender for Databases and Storage5q
- Implementing Agentless VM Scanning
- Implementing Agentless VM Scanning5q
- Managing Vulnerability Management for VMs
- Managing Vulnerability Management for VMs5q
- Configuring DevOps Security
- Configuring DevOps Security5q
- Managing Security Alerts
- Managing Security Alerts5q
- Configuring Workflow Automation
- Configuring Workflow Automation5q
- Configuring Data Collection Rules
- Configuring Data Collection Rules5q
- Configuring Sentinel Data Connectors
- Configuring Sentinel Data Connectors5q
- Enabling Analytics Rules in Sentinel
- Enabling Analytics Rules in Sentinel5q
- Configuring Automation in Sentinel
- Configuring Automation in Sentinel5q
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