你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Add-AzMetricAlertRuleV2
添加或更新基于 V2(非经典)指标的警报规则。
语法
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>]
说明
添加或更新 V2(非经典)基于指标的警报规则。 添加的规则与资源组相关联,并且具有名称。 此 cmdlet 实现 ShouldProcess 模式,即在实际创建、修改或删除资源之前,它可能会请求用户确认。
示例
示例 1:向虚拟机添加指标警报规则
$act = [Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup]::New("/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo")
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 的输出
示例 2:为订阅中的所有虚拟机添加指标警报规则
$act = [Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup]::New("/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo")
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 = [Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup]::New("/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-AzMetricAlertRuleV2DimensionSelection 和 New-AzMetricAlertRuleV2Criteria。
上述 cmdlet 集将创建包含维度的指标警报规则。
参数
-ActionGroup
规则的操作组
类型: | ActivityLogAlertActionGroup[] |
别名: | Actions |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-ActionGroupId
规则的操作组 ID
类型: | String[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-AutoMitigate
指示是否应自动解决警报的标志
类型: | Boolean |
Position: | Named |
默认值: | True |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Condition
规则的条件
类型: | List<T>[IPSMultiMetricCriteria] |
别名: | Criteria |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-DefaultProfile
用于与 Azure 通信的凭据、帐户、租户和订阅。
类型: | IAzureContextContainer |
别名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Description
指标警报规则的说明
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-DisableRule
禁用规则(状态)标志
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Frequency
规则的计算频率
类型: | TimeSpan |
别名: | EvaluationFrequency |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Name
指标警报规则的名称
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-ResourceGroupName
资源组名称
类型: | String |
别名: | ResourceGroup |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Severity
指标警报规则的严重性
类型: | Int32 |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-TargetResourceId
规则的目标资源 ID
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-TargetResourceRegion
规则的目标资源区域
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-TargetResourceScope
规则的目标资源范围
类型: | String[] |
别名: | Scopes |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-TargetResourceType
规则的目标资源类型
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-WindowSize
规则的窗口大小
类型: | TimeSpan |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
输入
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[]