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>]
Description
新增或更新 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
規則的動作群組標識碼
類型: | 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
規則的目標資源標識碼
類型: | 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[]