Add-AzMetricAlertRuleV2

新增或更新 V2 (非傳統) 計量型警示規則。

Syntax

Add-AzMetricAlertRuleV2
   -Name <String>
   -ResourceGroupName <String>
   -WindowSize <TimeSpan>
   -Frequency <TimeSpan>
   -TargetResourceId <String>
   -Condition <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Insights.OutputClasses.IPSMultiMetricCriteria]>
   [-AutoMitigate <Boolean>]
   [-ActionGroup <ActivityLogAlertActionGroup[]>]
   [-ActionGroupId <String[]>]
   [-DisableRule]
   [-Description <String>]
   -Severity <Int32>
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Add-AzMetricAlertRuleV2
   -Name <String>
   -ResourceGroupName <String>
   -WindowSize <TimeSpan>
   -Frequency <TimeSpan>
   -TargetResourceScope <String[]>
   -TargetResourceType <String>
   -TargetResourceRegion <String>
   -Condition <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Insights.OutputClasses.IPSMultiMetricCriteria]>
   [-AutoMitigate <Boolean>]
   [-ActionGroup <ActivityLogAlertActionGroup[]>]
   [-ActionGroupId <String[]>]
   [-DisableRule]
   [-Description <String>]
   -Severity <Int32>
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

新增或更新 V2 (非傳統) 計量型警示規則。 新增的規則與資源群組相關聯,且具有名稱。 此 Cmdlet 會實作 ShouldProcess 模式,也就是在實際建立、修改或移除資源之前,可能會要求使用者確認。

範例

範例 1:將計量警示規則新增至虛擬機器

Add-AzMetricAlertRuleV2 -Name PS3182019 -ResourceGroupName xxxxRG -WindowSize 0:5 -Frequency 0:5 -TargetResourceScope "/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM1", "/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM2" -TargetResourceType "Microsoft.Compute/virtualMachines" -TargetResourceRegion "eastus" -Description "This is description" -Severity 4 -ActionGroup $act -Condition $condition

Description          : This is description
Severity             : 4
Enabled              : True
Scopes               : {/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM1,
                       /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM2}
EvaluationFrequency  : 00:05:00
WindowSize           : 00:05:00
TargetResourceType   : Microsoft.Compute/virtualMachines
TargetResourceRegion : eastus
Criteria             : Microsoft.Azure.Management.Monitor.Models.MetricAlertMultipleResourceMultipleMetricCriteria
AutoMitigate         :
Actions              : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/demo}
LastUpdatedTime      :
Id                   : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/xxxxRG/providers/Microsoft.Insights/metricAlerts/PS3182019
Name                 : PS3182019
Type                 : Microsoft.Insights/metricAlerts
Location             : global
Tags                 :

此命令會建立虛擬機器的計量警示規則。 $condition是 New-AzMetricAlertRuleV2Criteria Cmdlet 的輸出,$act是 New-AzActionGroup Cmdlet 的輸出

範例 2:為訂用帳戶中的所有虛擬機器新增計量警示規則

Add-AzMetricAlertRuleV2 -Name AllVM -ResourceGroupName xxxxRG -WindowSize 0:5 -Frequency 0:5 -TargetResourceScope "/subscriptions/00000000-0000-0000-0000-0000000" -TargetResourceType "Microsoft.Compute/virtualMachines" -TargetResourceRegion "eastus" -Description "This is description" -Severity 4 -ActionGroup $act -Condition $condition

Description          : This is description
Severity             : 4
Enabled              : True
Scopes               : {/subscriptions/00000000-0000-0000-0000-0000000}
EvaluationFrequency  : 00:05:00
WindowSize           : 00:05:00
TargetResourceType   : Microsoft.Compute/virtualMachines
TargetResourceRegion : eastus
Criteria             : Microsoft.Azure.Management.Monitor.Models.MetricAlertMultipleResourceMultipleMetricCriteria
AutoMitigate         :
Actions              : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/demo}
LastUpdatedTime      :
Id                   : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/xxxxRG/providers/Microsoft.Insights/metricAlerts/AllVM
Name                 : AllVM
Type                 : Microsoft.Insights/metricAlerts
Location             : global
Tags                 :

此命令會針對 eastus 訂用帳戶中的所有虛擬機器建立計量警示規則

範例 3:停用計量警示規則

Get-AzMetricAlertRuleV2 -ResourceGroupName alertstest  -Name TestAlertRule | Add-AzMetricAlertRuleV2 -DisableRule

Description          : This new Metric alert rule was created from Powershell version: 1.0.1
Severity             : 4
Enabled              : False
Scopes               : {/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/components/alertstestFunction}
EvaluationFrequency  : 00:05:00
WindowSize           : 00:05:00
TargetResourceType   :
TargetResourceRegion :
Criteria             : Microsoft.Azure.Management.Monitor.Models.MetricAlertSingleResourceMultipleMetricCriteria
AutoMitigate         :
Actions              : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/demo1}
LastUpdatedTime      :
Id                   : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/metricAlerts/TestAlertRule
Name                 : TestAlertRule
Type                 : Microsoft.Insights/metricAlerts
Location             : global
Tags                 :

此命令會停用計量警示規則。 在這裡,我們會將 Get-AzMetricAlertRuleV2 的管線輸出傳送至 Add-AzMetricAlertRuleV2

範例 4:新增具有維度的計量警示規則

$act = New-AzActivityLogAlertActionGroupObject -Id "/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo"
$dim1 = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "availabilityResult/name" -ValuesToInclude "gdtest"
$dim2 = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "availabilityResult/location" -ValuesToInclude "*"
$criteria = New-AzMetricAlertRuleV2Criteria -MetricName "availabilityResults/availabilityPercentage" -DimensionSelection $dim1,$dim2 -TimeAggregation Average -Operator GreaterThan -Threshold 2
Add-AzMetricAlertRuleV2 -Name AlertWithDim -ResourceGroupName alertstest -WindowSize 00:05:00 -Frequency 00:05:00 -TargetResourceId "/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/components/alertstestFunction" -Condition $criteria -ActionGroup $act -DisableRule -Severity 4

Description          : This new Metric alert rule was created from Powershell version: 1.0.0
Severity             : 4
Enabled              : False
Scopes               : {/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/components/alertstestFunction}
EvaluationFrequency  : 00:05:00
WindowSize           : 00:05:00
TargetResourceType   :
TargetResourceRegion :
Criteria             : Microsoft.Azure.Management.Monitor.Models.MetricAlertSingleResourceMultipleMetricCriteria
AutoMitigate         :
Actions              : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo}
LastUpdatedTime      :
Id                   : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/metricAlerts/AlertWithDim
Name                 : AlertWithDim
Type                 : Microsoft.Insights/metricAlerts
Location             : global
Tags                 :

若要建立更複雜的計量警示規則,例如涉及選取維度值或有多個準則的警示規則,您可以使用 Helper Cmdlet New-AzMetricAlertRuleV2DimensionSelectionNew-AzMetricAlertRuleV2Criteria

上述一組 Cmdlet 會建立具有維度的計量警示規則。

參數

-ActionGroup

規則的動作群組

Type:ActivityLogAlertActionGroup[]
Aliases:Actions
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-ActionGroupId

規則的動作群組識別碼

Type:String[]
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-AutoMitigate

旗標,指出是否應該自動解決警示

Type:Boolean
Position:Named
Default value:True
Accept pipeline input:True
Accept wildcard characters:False

-Condition

規則的條件

Type:List<T>[IPSMultiMetricCriteria]
Aliases:Criteria
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-Confirm

在執行 Cmdlet 前提示您確認。

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

用於和 Azure 通訊的認證、帳戶、租用戶及訂用帳戶。

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-Description

計量警示規則的描述

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-DisableRule

停用規則 (狀態) 旗標

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-Frequency

規則的評估頻率

Type:TimeSpan
Aliases:EvaluationFrequency
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-Name

計量警示規則的名稱

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-ResourceGroupName

資源組名

Type:String
Aliases:ResourceGroup
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-Severity

計量警示規則的嚴重性

Type:Int32
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-TargetResourceId

規則的目標資源識別碼

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-TargetResourceRegion

規則的目標資源區域

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-TargetResourceScope

規則的目標資源範圍

Type:String[]
Aliases:Scopes
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-TargetResourceType

規則的目標資源類型

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

顯示執行 Cmdlet 後會發生的情況。 Cmdlet 並不會執行。

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-WindowSize

規則的視窗大小

Type:TimeSpan
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

輸入

String

TimeSpan

String[]

List<T>[[Microsoft.Azure.Commands.Insights.OutputClasses.IPSMultiMetricCriteria, Microsoft.Azure.PowerShell.Cmdlets.Monitor, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null]]

Microsoft.Azure.Management.Monitor.Models.ActivityLogAlertActionGroup[]

SwitchParameter

Int32

輸出

PSMetricAlertRuleV2