Exercise - Use diagnostic data

Completed

Azure enables you to take action on the metrics you're capturing. You can create alerts that email you, or start automations with runbooks.

Now, you'll create an alert based on your web server's CPU usage. If the CPU usage goes above the set threshold of 90 percent for five minutes, you get an email.

In this unit, you'll add an alert for your virtual machine (VM). Next, you'll cause the VM CPU usage to spike, and receive the alert email.

Create an alert based on CPU usage

If CPU usage goes above 90 percent for one minute, you'd like to get a notification.

  1. Go to the Azure portal.

  2. On the Azure portal menu, or from the Home page, select Virtual machines.

  3. Select the monitored-linux-vm virtual machine that you created. The monitored-linux-vm virtual machine pane appears.

  4. On the left menu pane, scroll down to Monitoring, and select Alerts. The Alerts pane appears for the monitored-linux-vm virtual machine.

  5. On the top menu, select Create > Alert rule.

    Screenshot that shows the menu selections for opening the Alerts pane and creating an Alert Rule for a virtual machine.

The Create an alert rule pane appears with the Select a signal pane open on the right.

Select the resource

When you open the Alerts pane from the menu of your virtual machine, the resource for your alert rule is automatically set to that virtual machine.

To verify, select the Scope tab on the Create an alert rule pane, and confirm that monitored-linux-vm is listed under Resource.

Screenshot that shows the VM selected on the pane for selecting a resource.

To set a different resource, you would choose Select scope and make the setting in the Select a resource pane.

Screenshot that shows the Select a resource pane.

Create the condition

  1. On the Create an alert rule pane, open the Condition tab, the Select a signal pane opens on the right.

  2. In the search box, search for and select Percentage CPU.

    Screenshot that shows 'Percentage CPU' selected as the signal name.

    The Create an alert rule pane reappears.

  3. Under Alert logic, confirm or enter the following values.

    Setting Value
    Threshold Static
    Aggregation type Average
    Operator Greater than or equal to
    Threshold value 90

    Screenshot that shows the section for alert logic filled out.

Add an action

  1. On the Create an alert rule pane, open the Actions tab and select Create action group. The Create an action group pane appears.

  2. On the Basics tab, enter the following values for each setting.

    Setting Value
    Project details
    Subscription Your subscription
    Resource group Resource group that contains the VM
    Region Global
    Instance details
    Action group name Email alerts

    Screenshot that shows the 'Add action group' pane filled out.

  3. Select Next: Notifications, and enter the following values for each setting.

    Setting Value
    Notifications
    Notification type Email/SMS/Push/Voice
    Name High CPU usage

    The Email/SMS message/Push/Voice pane appears.

  4. Tick the Email checkbox, and enter your email address to receive the alert notification. If this pane doesn't appear, select Edit for the notification type.

    Screenshot that shows the 'Email/SMS/Push/Voice' pane.

  5. On the Email/SMS message/Push/Voice pane, select OK.

  6. On the Create an action group pane, select Review + create, and then select Create. You should see a notification that your action group was successfully created.

Enter alert rule details

  1. On the Create an alert rule pane, select the Details tab and enter the following values for each setting.

    Setting Value
    Alert rule name Web server CPU running hot
    Alert rule description Email alert notifies when the CPU is over 90%

    Screenshot that shows the fields for alert details.

  2. Select Review + create, and then select Create. You should see a notification that your Alert rule was successfully created.

Trigger the alert

  1. In the left menu pane, go to the Overview pane for the monitored-linux-vm virtual machine.

  2. In the upper menu bar, select Connect, and then select SSH. The Connect pane for your VM appears.

    Screenshot that shows the 'Connect' button on the VM overview pane.

  3. Under step 4 on the Connect page, copy the azureuser@ and IP address that follows.

  4. In Azure Cloud Shell to the right, enter SSH, and paste what you copied in the previous step. It should look like the following command.

    ssh azureuser@<ipaddress>
    

    If Cloud Shell times out, select Reconnect.

  5. When you're prompted, enter yes to connect to the VM.

  6. Run the following command to update the list of available updates.

    sudo apt-get update
    
  7. Run the following command to install the stress tool on the VM.

    sudo apt-get install stress
    
  8. Run the following command to stress the VM's CPU.

    sudo stress --cpu 16 -v -t 10m
    
  9. Return to the Azure portal and in the upper left corner, select the icon, and then select Dashboard. The KPI Dashboard appears.

  10. On the Max cpu/usage_active for monitored-linux-vm graph, select the ellipses (...) on the upper right, and then select Refresh.

  11. After a few minutes, the CPU should approach 100 percent, and you'll receive an alert email.

    Screenshot of the alert email.