Exercise - Use diagnostic data
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.
Go to the Azure portal.
On the Azure portal menu, or from the Home page, select Virtual machines.
Select the monitored-linux-vm virtual machine that you created. The monitored-linux-vm virtual machine pane appears.
On the left menu pane, scroll down to Monitoring, and select Alerts. The Alerts pane appears for the monitored-linux-vm virtual machine.
On the top menu, select Create > Alert rule.
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.
To set a different resource, you would choose Select scope and make the setting in the Select a resource pane.
Create the condition
On the Create an alert rule pane, open the Condition tab, the Select a signal pane opens on the right.
In the search box, search for and select Percentage CPU.
The Create an alert rule pane reappears.
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
Add an action
On the Create an alert rule pane, open the Actions tab and select Create action group. The Create an action group pane appears.
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
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.
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.
On the Email/SMS message/Push/Voice pane, select OK.
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
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%
Select Review + create, and then select Create. You should see a notification that your Alert rule was successfully created.
Trigger the alert
In the left menu pane, go to the Overview pane for the monitored-linux-vm virtual machine.
In the upper menu bar, select Connect, and then select SSH. The Connect pane for your VM appears.
Under step 4 on the Connect page, copy the azureuser@ and IP address that follows.
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.
If Cloud Shell times out, select Reconnect.
When you're prompted, enter yes to connect to the VM.
Run the following command to update the list of available updates.
sudo apt-get update
Run the following command to install the stress tool on the VM.
sudo apt-get install stress
Run the following command to stress the VM's CPU.
sudo stress --cpu 16 -v -t 10m
Return to the Azure portal and in the upper left corner, select the ☰ icon, and then select Dashboard. The KPI Dashboard appears.
On the Max cpu/usage_active for monitored-linux-vm graph, select the ellipses (...) on the upper right, and then select Refresh.
After a few minutes, the CPU should approach 100 percent, and you'll receive an alert email.
Need help? See our troubleshooting guide or provide specific feedback by reporting an issue.