az monitor metrics alert

Manage near-realtime metric alert rules.

Commands

az monitor metrics alert create

Create a metric-based alert rule.

az monitor metrics alert delete

Delete a metrics-based alert rule.

az monitor metrics alert list

List metric-based alert rules.

az monitor metrics alert show

Show a metrics-based alert rule.

az monitor metrics alert update

Update a metric-based alert rule.

az monitor metrics alert create

Create a metric-based alert rule.

az monitor metrics alert create --condition
                                --name
                                --resource-group
                                --scopes
                                [--action]
                                [--auto-mitigate {false, true}]
                                [--description]
                                [--disabled {false, true}]
                                [--evaluation-frequency]
                                [--region]
                                [--severity]
                                [--subscription]
                                [--tags]
                                [--target-resource-type]
                                [--window-size]

Examples

Create a high CPU usage alert on a VM with no action.

az monitor metrics alert create -n alert1 -g {ResourceGroup} --scopes {VirtualMachineID} --condition "avg Percentage CPU > 90" --description "High CPU"

Create a high CPU usage alert on a VM with email and webhook actions.

az monitor metrics alert create -n alert1 -g {ResourceGroup} --scopes {VirtualMachineID} \
    --condition "avg Percentage CPU > 90" --window-size 5m --evaluation-frequency 1m \
    --action "/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Insights/actionGroups/<actionGroupName>" apiKey={APIKey} type=HighCPU \
    --description "High CPU"

Create an alert when a storage account shows a high number of slow transactions, using multi-dimensional filters.

az monitor metrics alert create -g {ResourceGroup} -n alert1 --scopes {StorageAccountId} \
    --description "Storage Slow Transactions" \
    --condition "total transactions > 5 where ResponseType includes Success" \
    --condition "avg SuccessE2ELatency > 250 where ApiName includes GetBlob"

Create a metric-based alert rule that monitors a custom metric.

az monitor metrics alert create -n "metric alert rule on a custom metric" -g "Demos" --scopes {VirtualMachineID} \
    --condition "max Azure.VM.Windows.GuestMetrics.Memory\Available Bytes > 90" \
    --window-size 5m --evaluation-frequency 1m

Create a high CPU usage alert on several VMs with no actions.

az monitor metrics alert create -n alert1 -g {ResourceGroup} --scopes {VirtualMachineID1} {VirtualMachineID2} {VirtualMachineID3} \
    --condition "avg Percentage CPU > 90" --description "High CPU"

Required Parameters

--condition

The condition which triggers the rule.

--name -n

Name of the alert rule.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--scopes

Space-separated list of scopes the rule applies to. The resources specified in this parameter must be of the same type and exist in the same location.

Optional Parameters

--action -a

Add an action group and optional webhook properties to fire when the alert is triggered.

--auto-mitigate

Automatically resolve the alert.

accepted values: false, true
--description

Free-text description of the rule.

--disabled

Create the rule in a disabled state.

accepted values: false, true
--evaluation-frequency

Frequency with which to evaluate the rule in "##h##m##s" format.

default value: 1m
--region --target-resource-region

The region of the target resource(s) in scopes. This must be provided when scopes is resource group or subscription.

--severity

Severity of the alert from 0 (critical) to 4 (verbose).

default value: 2
--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--tags

Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--target-resource-type --type

The resource type of the target resource(s) in scopes. This must be provided when scopes is resource group or subscription.

--window-size

Time over which to aggregate metrics in "##h##m##s" format.

default value: 5m

az monitor metrics alert delete

Delete a metrics-based alert rule.

az monitor metrics alert delete [--ids]
                                [--name]
                                [--resource-group]
                                [--subscription]

Examples

Delete a metrics-based alert rule. (autogenerated)

az monitor metrics alert delete --name MyAlertRule --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--name -n

Name of the alert rule.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor metrics alert list

List metric-based alert rules.

az monitor metrics alert list [--query-examples]
                              [--resource-group]
                              [--subscription]

Examples

List metric-based alert rules. (autogenerated)

az monitor metrics alert list --resource-group MyResourceGroup

Optional Parameters

--query-examples

Recommend JMESPath string for you. You can copy one of the query and paste it after --query parameter within double quotation marks to see the results. You can add one or more positional keywords so that we can give suggestions based on these key words.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor metrics alert show

Show a metrics-based alert rule.

az monitor metrics alert show [--ids]
                              [--name]
                              [--query-examples]
                              [--resource-group]
                              [--subscription]

Examples

Show a metrics-based alert rule. (autogenerated)

az monitor metrics alert show --name MyAlertRule --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--name -n

Name of the alert rule.

--query-examples

Recommend JMESPath string for you. You can copy one of the query and paste it after --query parameter within double quotation marks to see the results. You can add one or more positional keywords so that we can give suggestions based on these key words.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor metrics alert update

Update a metric-based alert rule.

az monitor metrics alert update [--add]
                                [--add-action]
                                [--add-condition]
                                [--auto-mitigate {false, true}]
                                [--description]
                                [--enabled {false, true}]
                                [--evaluation-frequency]
                                [--force-string]
                                [--ids]
                                [--name]
                                [--remove]
                                [--remove-actions]
                                [--remove-conditions]
                                [--resource-group]
                                [--scopes]
                                [--set]
                                [--severity]
                                [--subscription]
                                [--tags]
                                [--window-size]

Examples

Update a metric-based alert rule. (autogenerated)

az monitor metrics alert update --enabled true --name MyAlertRule --resource-group MyResourceGroup

Disable/Enable a metric-based alert rule.

az monitor metrics alert update --enabled false --name MyAlertRule --resource-group MyResourceGroup

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty <key=value, string or JSON string>.

--add-action

Add an action group and optional webhook properties to fire when the alert is triggered.

--add-condition

Add a condition which triggers the rule.

--auto-mitigate

Automatically resolve the alert.

accepted values: false, true
--description

Free-text description of the rule.

--enabled

Whether the metric alert rule is enabled.

accepted values: false, true
--evaluation-frequency

Frequency with which to evaluate the rule in "##h##m##s" format.

--force-string

When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--name -n

Name of the alert rule.

--remove

Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove.

--remove-actions

Space-separated list of action group names to remove.

--remove-conditions

Space-separated list of condition names to remove.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--scopes

Space-separated list of scopes the rule applies to. The resources specified in this parameter must be of the same type and exist in the same location.

--set

Update an object by specifying a property path and value to set. Example: --set property1.property2=.

--severity

Severity of the alert from 0 (critical) to 4 (verbose).

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--tags

Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--window-size

Time over which to aggregate metrics in "##h##m##s" format.