Monitor Azure Virtual Machines
This document provides comprehensive guidance on monitoring your Azure Virtual Machines (VMs) to ensure optimal performance, availability, and security.
Why Monitor Azure VMs?
Effective monitoring is crucial for understanding your VM's health and performance. It helps in:
- Detecting performance bottlenecks.
- Identifying potential issues before they impact users.
- Troubleshooting problems efficiently.
- Ensuring compliance and security posture.
- Optimizing resource utilization and costs.
Key Monitoring Tools and Services
Azure Monitor
Azure Monitor is the foundational service for collecting, analyzing, and acting on telemetry from your Azure and on-premises environments. It provides a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments.
- Metrics: Time-series numerical data representing the health and performance of your VM. Common metrics include CPU utilization, memory usage, disk I/O, and network traffic.
- Logs: Structured event data that can be queried for deeper insights. This includes performance counters, event logs, and custom application logs.
- Alerts: Proactive notifications triggered when specific conditions are met based on metrics or logs.
- Dashboards: Customizable visualizations of your VM's performance and health data.
VM Insights
VM Insights is a feature within Azure Monitor that provides performance and health monitoring for your Azure VMs and Azure Scale Sets. It leverages Azure Monitor's data collection and analysis capabilities to offer pre-built workbooks for common monitoring scenarios.
- Performance Analysis: Out-of-the-box charts for CPU, memory, disk, and network.
- Dependency Mapping: Visualizes network connections between VMs and external services.
- Log Analytics Integration: Deep dive into logs for troubleshooting.
Collecting VM Data
Log Analytics Agent / Azure Monitor Agent
To collect logs and performance counters from your VMs, you need to install an agent. The Azure Monitor Agent (AMA) is the recommended agent for new deployments, replacing the legacy Log Analytics Agent.
Log Analytics Agent (legacy):
# Example: Enable performance counters for collection
az vm extension set --resource-group MyResourceGroup --vm-name MyVM --name Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent --publisher Microsoft.EnterpriseCloud.Monitoring --version 1.0 --settings '{"xmlCfg": "...", "omsAgentVersion": "1.13.5-0"}'
Azure Monitor Agent (recommended):
Configure data collection rules (DCRs) to specify which data to collect from your VMs and where to send it.
Key Metrics to Monitor
Focus on these critical metrics for a healthy VM:
| Metric | Description | Typical Threshold |
|---|---|---|
| % CPU utilization | Percentage of time the CPU is busy executing threads. | < 80% (sustained) |
| % Disk Read/Write Bytes/sec | Rate of data being read from or written to the disk. | Depends on disk type and workload |
| % Disk Read/Write Operations/sec | Number of read or write operations per second. | Depends on disk type and workload |
| Network In/Out (Bytes/sec) | Data transfer rate to and from the VM. | Depends on application needs |
| Available Memory (Bytes) | Amount of physical memory available to the operating system. | > 200MB (Windows), > 100MB (Linux) |
| RDP/SSH connection failures | Failed connection attempts to the VM. | 0 (ideally) |
Configuring Alerts
Set up alerts to be notified immediately when issues arise. Azure Monitor allows you to create alerts based on metrics, log queries, and activity logs.
- Navigate to Azure Monitor in the Azure portal.
- Select 'Alerts' and then 'Create alert rule'.
- Define the scope (your VM or resource group).
- Configure the condition (e.g., CPU utilization > 90% for 15 minutes).
- Define the action group (e.g., send an email, trigger a webhook).
- Name and save the alert rule.
Using Dashboards and Workbooks
Visualize your VM data effectively:
- Azure Dashboards: Pin important metrics and charts from Azure Monitor to a custom dashboard for a quick overview.
- Workbooks: Create interactive reports combining metrics, logs, and text in Azure Monitor Workbooks. VM Insights provides pre-built workbooks for performance analysis and dependency mapping.
Accessing VM Insights workbooks:
- In the Azure portal, navigate to your VM.
- Under the 'Monitoring' section, select 'Insights'.
- Explore the 'Performance' and 'Map' tabs.
Monitoring VM Health with Azure Advisor
Azure Advisor provides personalized recommendations for optimizing your Azure resources, including VMs. It offers recommendations related to performance, cost, security, high availability, and operational excellence.