Complete Guide to Monitoring and Troubleshooting Network Health
Azure Network Watcher provides tools to monitor, diagnose, view metrics, and enable or disable logs for resources in an Azure virtual network. It's designed to monitor and repair the network health of IaaS (Infrastructure-as-a-Service) products including Virtual Machines, Virtual Networks, Application Gateways, Load balancers, etc.
Monitor communication between a virtual machine and an endpoint using Connection Monitor
Analyze network traffic patterns and identify security threats
Troubleshoot VPN connectivity, routing issues, and network security groups
Capture network packets and analyze performance bottlenecks
Network Watcher must be enabled in each region where you want to monitor networks. By default, it's automatically enabled when you create a virtual network.
# Enable Network Watcher in a specific region
az network watcher configure \
--resource-group myNetworkWatcherRG \
--locations eastus \
--enabled true
--resource-group
: Resource group where Network Watcher will be created--locations
: Azure regions where you want to enable Network Watcher--enabled true
: Enables Network Watcher in the specified regions# Create a dedicated resource group for Network Watcher
az group create \
--name NetworkWatcherRG \
--location eastus
--name
: Name of the resource group (recommended: NetworkWatcherRG)--location
: Azure region for the resource group# Create storage account for storing network monitoring data
az storage account create \
--name networkwatcherstorage001 \
--resource-group NetworkWatcherRG \
--location eastus \
--sku Standard_LRS \
--kind StorageV2
--name
: Globally unique storage account name (must be lowercase, 3-24 characters)--sku Standard_LRS
: Locally Redundant Storage (cost-effective for logs)--kind StorageV2
: General-purpose v2 storage account (recommended)Connection Monitor provides unified end-to-end connection monitoring in Azure Network Watcher. It monitors communication between Azure and hybrid endpoints.
# Create a connection monitor
az network watcher connection-monitor create \
--name "VM-to-Website-Monitor" \
--resource-group NetworkWatcherRG \
--location eastus
--name
: Descriptive name for the connection monitor--resource-group
: Resource group containing Network Watcher--location
: Region where Network Watcher is enabled# Add source endpoint (Azure VM)
az network watcher connection-monitor endpoint add \
--connection-monitor "VM-to-Website-Monitor" \
--location eastus \
--name "source-vm" \
--resource-id "/subscriptions/{subscription}/resourceGroups/myRG/providers/Microsoft.Compute/virtualMachines/myVM"
--connection-monitor
: Name of the connection monitor created earlier--name
: Friendly name for this endpoint--resource-id
: Full Azure resource ID of the source VM# Add destination endpoint (external website)
az network watcher connection-monitor endpoint add \
--connection-monitor "VM-to-Website-Monitor" \
--location eastus \
--name "target-website" \
--address "www.microsoft.com"
--address
: External address (FQDN or IP) to monitorNetwork Security Group (NSG) flow logs capture information about IP traffic flowing through NSGs. They provide deep insights into network traffic patterns.
# Enable NSG flow logs
az network watcher flow-log configure \
--resource-group myResourceGroup \
--nsg myNetworkSecurityGroup \
--storage-account networkwatcherstorage001 \
--enabled true \
--retention 30
--nsg
: Name of the Network Security Group to monitor--storage-account
: Storage account for storing flow logs--enabled true
: Enables flow logging--retention 30
: Retains logs for 30 days (0-365 days)# Enable flow logs with Traffic Analytics
az network watcher flow-log create \
--name "MyNSGFlowLog" \
--nsg "/subscriptions/{subscription}/resourceGroups/myRG/providers/Microsoft.Network/networkSecurityGroups/myNSG" \
--storage-account "/subscriptions/{subscription}/resourceGroups/NetworkWatcherRG/providers/Microsoft.Storage/storageAccounts/networkwatcherstorage001" \
--resource