Exercise - Set up a VM with boot diagnostics
When you run your virtual machine (VM) on Azure, you can view basic metrics without installing any extra software. You can quickly create a VM by using the Azure portal, the Azure CLI, or PowerShell. You can connect boot diagnostics when you create the VM.
You want to move to a new version of Ubuntu, so you deploy a new VM. You need to monitor only the basic metrics. So you're going to create only a VM and a storage account.
In this exercise, you deploy a Linux VM and enable boot diagnostics. After the VM is created, you quickly set up a graph to view the CPU usage and inbound traffic. You also check that the boot diagnostics are working correctly.
You need an Azure subscription to complete these exercises. If you don't have an Azure subscription, create a free account and add a subscription before you begin. If you are a student, you can take advantage of the Azure for students offer.
Task 1: Create a storage account and VM
Sign in to the Azure portal.
From the top right-hand side of the Azure portal, select Cloud Shell.
In Cloud Shell, select Bash.
Create a resource group by running the following command where you replace the placeholders with a location like eastus2 and resource group name like learn-monitor-vm-rg.
LOCATION=<region> RESOURCEGROUP=<resource-group-name> az group create \ --name $RESOURCEGROUP \ --location $LOCATION
Run the following command in Azure Cloud Shell to create a storage account to store boot diagnostics.
STORAGE=metricsstorage$RANDOM az storage account create \ --name $STORAGE \ --sku Standard_LRS \ --location $LOCATION \ --resource-group $RESOURCEGROUP
Run the following command to create your VM with boot diagnostics enabled.
az vm create \ --name monitored-linux-vm \ --image UbuntuLTS \ --size Standard_B1s \ --location $LOCATION \ --admin-username azureuser \ --boot-diagnostics-storage $STORAGE \ --resource-group $RESOURCEGROUP \ --generate-ssh-keys
Creating the VM might take a couple of minutes.
Task 2: View basic metrics for the VM
Go to the Azure portal.
On the Azure portal menu or from the Home page, select Virtual machines. The Virtual machines pane appears.
Select the monitored-linux-vm virtual machine that you created. The monitored-linux-vm virtual machine pane appears.
In the middle menu pane, scroll down, and under Monitoring, select Metrics. The Metrics pane appears for your monitored-linux-vm VM.
Select the following values for each setting:
Setting Value Metric Namespace Virtual Machine Host Metric Percentage CPU Aggregation Max Select Add metric.
Select the following values for each setting:
Setting Value Metric Namespace Virtual Machine Host Metric Inbound Flows Aggregation Avg In the upper right, select the Local Time: Last 24 hours (Automatic - 5 minutes) setting, and under Time Range, change to Last 30 minutes, and select Apply.
You should now have a graph that looks something like the following screenshot:
Azure collects this data without requiring you to install anything extra on Ubuntu or Windows VMs.
Task 3: View boot diagnostics
In the middle menu pane, under Help, select Boot diagnostics.
In the upper menu bar, select Settings. The Boot diagnostics pane appears.
Under Status, select Enable with managed storage account (recommended). In the top menu bar, select Save.
After you receive the notification Successfully updated boot diagnostic settings, return to the Boot diagnostics pane for your virtual machine. Select Refresh in the top menu bar, and review the screenshot to verify that your virtual machine has started correctly.
You can also select Serial log to view log messages created when the VM started.
Need help? See our troubleshooting guide or provide specific feedback by reporting an issue.