0

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.

DnyaneshSurya
  • 187
  • 1
  • 1
  • 14

1 Answers1

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:

kobulloc
  • 251
  • 1
  • 3