【问题标题】:How to create Azure Monitor - Alerts for virtual machine using Azure .Net SDK or Powershell scripts如何创建 Azure Monitor - 使用 Azure .Net SDK 或 Powershell 脚本的虚拟机警报
【发布时间】:2021-09-28 17:00:23
【问题描述】:

我想创建 Azure Monitor - 虚拟机磁盘利用率、CPU 使用率等警报。 那么有什么方法或任何 Azure .net sdk 可以帮助我解决这个问题。

【问题讨论】:

    标签: powershell arm-template azure-sdk-.net azure-fluent-api


    【解决方案1】:

    Azure Monitor 支持使用 Azure CLI 和 Azure PowerShell 在门户中创建警报(还有一些使用 REST API 的交互):

    这是在经典 VM 上创建 CPU% 指标警报的示例:

    https://docs.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
    

    其他 Azure Monitor PowerShell 资源:

    【讨论】:

      猜你喜欢
      • 2021-03-08
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 2019-08-30
      • 2019-05-10
      相关资源
      最近更新 更多