Cloud Computing guides, explanations and reader checklists on whilenetworking.com

Azure Log Analytics Setup: Creating Custom Dashboards for Correlating Application Logs with Infrastructure Metrics

In modern hybrid cloud environments, the ability to correlate application-level errors with underlying infrastructure performance is critical for rapid…

In modern hybrid cloud environments, the ability to correlate application-level errors with underlying infrastructure performance is critical for rapid incident resolution. When an application times out, knowing whether the cause is a database query bottleneck, a network latency spike, or a container resource exhaustion requires a unified view of data. Azure Log Analytics provides this capability through its powerful Kusto Query Language (KQL) engine. This guide demonstrates how to set up a custom dashboard that ingests both infrastructure metrics and application logs, allowing you to visualize the relationship between system health and application behavior.

Prerequisites and Architecture Overview

Before configuring the solution, ensure your Azure environment meets specific requirements. You will need an active subscription with access to create Resource Groups, Log Analytics Workspaces, and Monitor resources. The architecture relies on two primary data sources:
1. Infrastructure Metrics: Automatically collected by Azure Monitor Agent (AMA) or legacy Azure Guest Agent from VMs or Container Instances.
2. Application Logs: Sent via Application Insights telemetry or custom log streams ingested into the Log Analytics workspace.

For this lab scenario, we will assume a Linux-based Virtual Machine hosting a web application. The setup involves enabling the Azure Monitor Agent, configuring an Application Insights resource for app logs, and linking both to a single Log Analytics Workspace. Note that while this guide focuses on Azure, the principles of correlating metrics and logs apply broadly to multi-cloud strategies involving AWS or hybrid infrastructure.

Step 1: Configure the Log Analytics Workspace and Data Sources

The foundation of any monitoring solution is a centralized workspace. Navigate to the Azure Portal and select Log Analytics workspaces. Create a new workspace within a dedicated resource group, such as rg-monitoring-lab. This workspace will serve as the central repository for all telemetry data.

Next, configure the data ingestion pipelines:
* Infrastructure: Ensure the Azure Monitor Agent is installed on your target VMs. In the Azure portal, go to the VM blade, select Monitoring, and verify that the agent is running. This agent automatically streams CPU, memory, disk, and network metrics to the workspace.
* Application: Create an Application Insights resource in the same region. In its settings, ensure “Live Metrics” and “Performance Counters” are enabled. To send logs to Log Analytics, navigate to the Application Insights blade, select Settings, then Data ingestion, and enable the option to stream data to your specific Log Analytics workspace.

Step 2: Develop a Correlation Query in Kusto Query Language (KQL)

The power of Log Analytics lies in its query language. To correlate infrastructure with application data, you must construct a query that joins these distinct datasets. Azure Monitor metrics are stored in the AzureMetrics table, while custom logs reside in the Logs table.

Below is a practical example of a KQL query designed to find instances where high CPU usage correlates with increased 5xx HTTP errors. This assumes you have an Application Insights telemetry stream mapped to the workspace.

// Query: Correlate High CPU with App Errors
let TimeRange = ago(1h)..now();
AzureMetrics
| where ResourceURI =~ "/subscriptions/*/resourceGroups/rg-monitoring-lab/providers/Microsoft.Compute/virtualMachines/my-web-vm"
| extend AvgCpuPercent = avg(CpuPercent)
| summarize AvgCpu by bin(TimeGenerated, 5m)
| join kind=inner (
    Logs
    | where TimeGenerated >= startTime and TimeGenerated <= endTime
    | where _Source == "MyApp" // Replace with your actual app name
    | where Properties_StatusCode == 500
    | summarize CountOfErrors = count() by bin(TimeGenerated, 5m)
) on TimeGenerated
| where AvgCpu > 80 and CountOfErrors > 10
| order by TimeGenerated desc
| project TimeGenerated, AvgCpu, CountOfErrors

Explanation of the Query Logic:
1. Filtering: The query first filters AzureMetrics for a specific VM resource URI.
2. Aggregation: It calculates the average CPU percentage over 5-minute bins.
3. Joining: It performs an inner join with the Logs table, filtering for specific application error codes (e.g., 500).
4. Condition: The final projection only shows rows where CPU exceeds 80% and error counts exceed 10 in the same time window.

Illustrative Output:
| TimeGenerated | AvgCpu | CountOfErrors |
| :— | :— | :— |
| 2023-10-27T14:05:00Z | 92.4 | 15 |
| 2023-10-27T14:10:00Z | 88.1 | 12 |

Step 3: Build the Custom Dashboard

Once the query is validated, you can create a dashboard to visualize these findings over time. In the Azure portal, navigate to your Log Analytics workspace and select Dashboards. Click + Add to create a new blank dashboard.

Add a new tile and paste the KQL query developed in the previous step into the Query field. Configure the tile properties:
* Name: “High CPU vs App Errors Correlation”
* Time range: Set this dynamically or to the last 24 hours for historical analysis.
* Visualization Type: Select a line chart to see trends, or a table for specific event logs.

You can add additional tiles to create a comprehensive view. For instance, add a separate tile displaying a simple metric summary of total CPU usage per VM without the join logic, allowing operators to quickly assess overall cluster health before diving into correlation details. Save the dashboard and share it with your incident response team.

Step 4: Verification and Common Errors

After deployment, verification is essential. Simulate a load test on your application or introduce artificial latency to trigger high CPU usage. Observe if the dashboard updates within the expected ingestion delay (usually under 15 seconds for live metrics).

Common Errors and Fixes:
* Error: “Invalid table name”: This often occurs if you are mixing legacy metric names with new AMA schema. Ensure you are querying AzureMetrics or ContainerMetrics depending on your agent version.
* Error: “Join failed due to different time columns”: Azure metrics and logs might have slight timestamp discrepancies. Use the TimeGenerated column consistently or apply a small buffer in the join logic if necessary.
* Performance Issues: If the dashboard loads slowly, the query may be scanning too much data. Always filter by ResourceURI or specific resource IDs to narrow the scope before performing joins.

Student Practice Task and Industry Application

For Students:
Set up a local lab using Azure Free Tier accounts. Create a small VM, install a simple web server (like Nginx), and configure an Application Insights instance. Attempt to replicate the correlation query above. Challenge yourself to modify the query to detect high memory usage instead of CPU, and correlate it with database connection pool exhaustion logs.

For Industry Practitioners:
In production environments, these dashboards are vital for Cost Controls. By correlating expensive infrastructure spikes (high CPU/memory) with application errors, teams can justify scaling resources or optimizing code paths to reduce monthly spend. Furthermore, this setup enhances security posture; sudden spikes in error counts combined with unusual network metrics can indicate a DDoS attack or compromised container, allowing the Security Operations Center (SOC) to react immediately.

Conclusion

Creating custom dashboards in Azure Log Analytics that correlate application logs with infrastructure metrics transforms raw telemetry into actionable intelligence. By following the steps to configure data sources, crafting precise KQL queries, and building visual tiles, IT professionals can significantly reduce Mean Time to Resolution (MTTR). While this guide focuses on Azure, the methodology of unifying logs and metrics is a universal best practice applicable to AWS CloudWatch or hybrid Kubernetes clusters. Always remember to validate your queries against real-time data and adhere to security best practices when sharing dashboards containing sensitive error details.

Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.