我想创建Azure Monitor-虚拟机磁盘利用率、CPU使用率等警报。那么,有什么方法或任何Azure.net sdk可以帮助我吗。
Azure Monitor支持使用Azure CLI和Azure PowerShell在门户中创建警报(还有一些使用REST API的交互(:
- Azure PowerShell
- Azure CLI
- REST API
这是在经典VM上创建CPU%度量警报的示例:
https://learn.microsoft.com/en-us/azure/azure-monitor/powershell-samples#create-度量警报
# 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
其他Azure Monitor PowerShell资源:
- Microsoft文档:Azure Monitor PowerShell示例
- Microsoft文档:使用Azure Monitor创建、查看和管理度量警报>PowerShell
- Microsoft文档:使用Azure Monitor创建、查看和管理日志警报>PowerShell
- Microsoft文档:使用Azure Monitor创建、查看和管理活动日志警报>PowerShell