I want to create Azure Monitor - Alerts for virtual machine disk utilization, CPU usage etc. So Is there any way or any Azure .net sdk which will help me on this.
Asked
Active
Viewed 276 times
1 Answers
0
Azure Monitor supports creating alerts in the Portal, with Azure CLI, and with Azure PowerShell (there are also some interactions using the REST API):
This is the example to create a CPU% metric alert on a classic VM:
https://learn.microsoft.com/en-us/azure/azure-monitor/powershell-samples#create-metric-alerts
# Create an Email action
$actionEmail = New-AzAlertRuleEmail -CustomEmail myname@company.com
# Create a Webhook action
$actionWebhook = New-AzAlertRuleWebhook -ServiceUri https://example.com?token=mytoken
# Create the alert rule on the CPU% metric on a classic VM
Add-AzMetricAlertRule -Name vmcpu_gt_1 -Location "East US" -ResourceGroup myrg1 -TargetResourceId /subscriptions/s1/resourceGroups/myrg1/providers/Microsoft.ClassicCompute/virtualMachines/my_vm1 -MetricName "Percentage CPU" -Operator GreaterThan -Threshold 1 -WindowSize 00:05:00 -TimeAggregationOperator Average -Action $actionEmail, $actionWebhook -Description "alert on CPU > 1%"
# Retrieve the alert rule
Get-AzAlertRule -Name vmcpu_gt_1 -ResourceGroup myrg1 -DetailedOutput
Additional Azure Monitor PowerShell Resources:
- Microsoft Docs: Azure Monitor PowerShell samples
- Microsoft Docs: Create, view, and manage metric alerts using Azure Monitor > PowerShell
- Microsoft Docs: Create, view, and manage log alerts using Azure Monitor > PowerShell
- Microsoft Docs: Create, view, and manage activity log alerts by using Azure Monitor > PowerShell

kobulloc
- 251
- 1
- 3