Note: Classic Style alerts are scheduled to be depricated June 30, 2019. Read more about this here: https://docs.microsoft.com/en-us/azure/azure-monitor/platform/monitoring-classic-retirement
For an example on how to create the new-style of alerts in Azure Monitor, go here: /~https://github.com/ssemyan/CreateAzureMonitorVmAlerts
This PowerShell script and ARM templates will create classic-style Azure alerts that email specified addresses when:
- The memory usage of the VM exceeds 80% for 5 minutes
- The CPU usage of the VM exceeds 80% for 5 minutes
- The network in of the VM falls below 15K for 5 minutes
The PowerShell script will set these alerts for every VM in the specified resource groups. This requires the VM Guest Diagnostics extension to be installed. Learn more about this here:
- Windows - https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-windows
- Linux - https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux
To install the Windows VM Extension while creating the alerts, set the value of $addExtension to $TRUE and update the values for $existingdiagnosticsStorageAccountName and $existingdiagnosticsStorageResourceGroup
To only install the extension and not create alerts, set the value of $addAlerts to $FALSE
To use this script edit the details in CreateAlertsOnAllVmsInResourceGroups.ps1:
First update the list of resource groups to search:
$resourceGroupsToProcess = @('my_group', 'my_group_2')
Alternatively, if you want to run against all resource groups uncomment out this line:
#$resourceGroupsToProcess = @()
Then update the email(s) to send alerts to (comma-separated if more than one):
$sendToEmails = 'myemail@company.com,myemail2@company.com'
Finally, run the following command in PowerShell. Note: this requires the Azure PowerShell Module and if using the new version, the script will set the AzureRm alias via Enable-AzureRmAlias.
.\CreateAlertsOnAllVmsInResourceGroups.ps1