您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure Monitor 创建、查看和管理指标警报Create, view, and manage metric alerts using Azure Monitor

Azure Monitor 中的指标警报提供了一种在指标超出阈值时获得通知的方式。Metric alerts in Azure Monitor provide a way to get notified when one of your metrics crosses a threshold. 指标警报适用于一系列多维平台指标、自定义指标、Application Insights 标准指标和自定义指标。Metric alerts work on a range of multi-dimensional platform metrics, custom metrics, Application Insights standard and custom metrics. 本文将介绍如何通过 Azure 门户和 Azure CLI 创建、查看和管理指标警报规则。In this article, we will describe how to create, view, and manage metric alert rules through Azure portal and Azure CLI. 也可以使用 Azure 资源管理器模板创建指标警报规则,另外的文章将会介绍此方法。You can also create metric alert rules using Azure Resource Manager templates, which are described in a separate article.

可以在指标警报概述中详细了解指标警报的工作原理。You can learn more about how metric alerts work from metric alerts overview.

使用 Azure 门户进行创建Create with Azure portal

以下过程说明如何在 Azure 门户中创建指标警报规则:The following procedure describes how to create a metric alert rule in Azure portal:

  1. Azure 门户中单击“监视”。 In Azure portal, click on Monitor. “监视”边栏选项卡将所有监视设置和数据合并到一个视图中。The Monitor blade consolidates all your monitoring settings and data in one view.

  2. 依次单击“警报”、“+ 新建警报规则”。 Click Alerts then click + New alert rule.


    大多数资源边栏选项卡的资源菜单中的“监视”下面也包含“警报”,同样可从中创建警报。 Most resource blades also have Alerts in their resource menu under Monitoring, you could create alerts from there as well.

  3. 在加载的上下文窗格中单击“选择目标”,选择要发出警报的目标资源 。Click Select target, in the context pane that loads, select a target resource that you want to alert on. 使用“订阅”和“资源类型”下拉列表查找要监视的资源。 Use Subscription and Resource type drop-downs to find the resource you want to monitor. 也可以使用搜索栏查找资源。You can also use the search bar to find your resource.

  4. 如果选定的资源具有可创建警报的指标,则右下方的“可用信号”将包含这些指标。 If the selected resource has metrics you can create alerts on, Available signals on the bottom right will include metrics. 可在此文中查看指标警报支持的资源类型的完整列表。You can view the full list of resource types supported for metric alerts in this article.

  5. 选择目标资源后,单击“添加条件” 。Once you have selected a target resource, click on Add condition.

  6. 此时会显示资源支持的信号列表,请选择要为其创建警报的指标。You will see a list of signals supported for the resource, select the metric you want to create an alert on.

  7. 随后会该指标在显示过去 6 小时的图表。You will see a chart for the metric for the last six hours. 可以使用“图表期间” 下拉框进行选择以查看更长时间的指标历史记录。Use the Chart period dropdown to select to see longer history for the metric.

  8. 如果指标包含维度,则会显示一个维度表。If the metric has dimensions, you will see a dimensions table presented. 为每个维度选择一个或多个值。Select one or more values per dimension.

    • 显示的维度值基于在过去 3 天内的指标数据。The displayed dimension values are based on metric data from the last three days.
    • 如果你要查看的维度值没有显示,请单击“+”来添加自定义值。If the dimension value you're looking for isn't displayed, click "+" to add a custom value.
    • 您还可以为任何维度*选择 * *""。You can also *Select * for any of the dimensions. *选择 * * 会将所选内容动态缩放到维度的所有当前和未来值。Select * will dynamically scale the selection to all current and future values for a dimension.

    指标警报规则将会针对所选值的所有组合对条件进行评估。The metric alert rule will evaluate the condition for all combinations of values selected. 详细了解如何针对多维指标发出警报Learn more about how alerting on multi-dimensional metrics works.

  9. 选择 _阈值* 类型、 运算符聚合类型Select the _Threshold* type, Operator, and Aggregation type. 这将确定指标警报规则将评估的逻辑。This will determine the logic that the metric alert rule will evaluate.

    • 如果使用“静态” 阈值,请继续定义“阈值” 。If you are using a Static threshold, continue to define a Threshold value. 指标图表可以帮助你确定可能合理的阈值。The metric chart can help determine what might be a reasonable threshold.
    • 如果使用“动态” 阈值,请继续定义“阈值敏感度” 。If you are using a Dynamic threshold, continue to define the Threshold sensitivity. 指标图表将显示基于最新数据计算得出的阈值。The metric chart will display the calculated thresholds based on recent data. 详细了解动态阈值条件类型和敏感度选项Learn more about Dynamic Thresholds condition type and sensitivity options.
  10. (可选)通过调整“聚合粒度” 和“评估频率” 来优化条件。Optionally, refine the condition by adjusting Aggregation granularity and Frequency of evaluation.

  11. 单击“完成” 。Click Done.

  12. (可选)若要监视复杂的预警规则,请添加另一个条件。Optionally, add another criteria if you want to monitor a complex alert rule. 目前,用户可以将包含动态阈值条件的预警规则用作单一条件。Currently users can have alert rules with Dynamic Thresholds criteria as a single criterion.

  13. 填写警报 详细信息 ,如 警报规则名称描述严重性Fill in Alert details like Alert rule name, Description, and Severity.

  14. 通过选择现有操作组或创建新的操作组,将一个操作组添加到警报中。Add an action group to the alert either by selecting an existing action group or creating a new action group.

  15. 单击“完成”保存指标警报规则。 Click Done to save the metric alert rule.


通过门户创建的指标警报规则将在目标资源所在的同一个资源组中创建。Metric alert rules created through portal are created in the same resource group as the target resource.

使用 Azure 门户查看和管理View and manage with Azure portal

可以使用“警报”下的“管理规则”边栏选项卡查看和管理指标警报规则。You can view and manage metric alert rules using the Manage Rules blade under Alerts. 以下过程说明如何查看指标警报规则,以及编辑其中的某个规则。The procedure below shows you how to view your metric alert rules and edit one of them.

  1. 在 Azure 门户中导航到“监视” In Azure portal, navigate to Monitor

  2. 单击“警报”和“管理规则” Click on Alerts and Manage rules

  3. 在“管理规则”边栏选项卡中,可以查看不同订阅中的所有警报规则。 In the Manage rules blade, you can view all your alert rules across subscriptions. 可以使用“资源组”、“资源类型”和“资源”进一步筛选规则。 You can further filter the rules using Resource group, Resource type, and Resource. 如果只想查看指标警报,请选择“指标”作为“信号类型”。 If you want to see only metric alerts, select Signal type as Metrics.


    在“管理规则”边栏选项卡中,可以选择多个警报规则并启用/禁用它们。 In the Manage rules blade, you can select multiple alert rules and enable/disable them. 需要将某些目标资源置于维护模式时,此功能可能十分有用This might be useful when certain target resources need to be put under maintenance

  4. 单击要编辑的指标警报规则的名称Click on the name of the metric alert rule you want to edit

  5. 在“编辑规则”中,单击要编辑的“警报条件”。 In the Edit Rule, click on the Alert criteria you want to edit. 可根据需要更改指标、阈值条件和其他字段You can change the metric, threshold condition and other fields as required


    创建指标警报后,无法编辑“目标资源”和“警报规则名称”。 You can't edit the Target resource and Alert Rule Name after the metric alert is created.

  6. 单击“完成”保存所做的编辑。 Click Done to save your edits.

使用 Azure CLIWith Azure CLI

前面几个部分介绍了如何使用 Azure 门户创建、查看和管理指标警报规则。The previous sections described how to create, view, and manage metric alert rules using Azure portal. 本部分将介绍如何使用跨平台 Azure CLI 实现相同的结果。This section will describe how to do the same using cross-platform Azure CLI. 使用 Azure CLI 的最快捷方式是通过 Azure Cloud ShellQuickest way to start using Azure CLI is through Azure Cloud Shell. 对于本文,我们将使用 Cloud Shell。For this article, we will use Cloud Shell.

  1. 请参阅 Azure 门户,单击 Cloud ShellGo to Azure portal, click on Cloud Shell.

  2. 在提示符下,可以结合 --help 选项使用命令来详细了解相应的命令及其用法。At the prompt, you can use commands with --help option to learn more about the command and how to use it. 例如,以下命令显示可用于创建、查看和管理指标警报的命令列表For example, the following command shows you the list of commands available for creating, viewing, and managing metric alerts

    az monitor metrics alert --help
  3. 可以创建一个简单的指标预警规则来监视 VM 上的平均 CPU 百分比是否大于 90You can create a simple metric alert rule that monitors if average Percentage CPU on a VM is greater than 90

    az monitor metrics alert create -n {nameofthealert} -g {ResourceGroup} --scopes {VirtualMachineResourceID} --condition "avg Percentage CPU > 90" --description {descriptionofthealert}
  4. 可以使用以下命令查看资源组中的所有指标警报You can view all the metric alerts in a resource group using the following command

    az monitor metrics alert list  -g {ResourceGroup}
  5. 可以使用规则的名称或资源 ID 查看特定指标警报规则的详细信息。You can see the details of a particular metric alert rule using the name or the resource ID of the rule.

    az monitor metrics alert show -g {ResourceGroup} -n {AlertRuleName}
    az monitor metrics alert show --ids {RuleResourceId}
  6. 可以使用以下命令禁用指标警报规则。You can disable a metric alert rule using the following command.

    az monitor metrics alert update -g {ResourceGroup} -n {AlertRuleName} --enabled false
  7. 可以使用以下命令删除指标警报规则。You can delete a metric alert rule using the following command.

    az monitor metrics alert delete -g {ResourceGroup} -n {AlertRuleName}

使用 PowerShellWith PowerShell

指标警报规则提供专用的 PowerShell cmdlet:Metric alert rules have dedicated PowerShell cmdlets available:


  • 创建或更新:新建指标警报规则或更新现有指标警报规则。Create Or Update: Create a new metric alert rule or update an existing one.
  • 获取:获取特定指标警报规则。Get: Get a specific metric alert rule.
  • 按资源组列出:获取特定资源组中的指标警报规则的列表。List By Resource Group: Get a list of metric alert rules in a specific resource group.
  • 按订阅列出:获取特定订阅中的指标警报规则的列表。List By Subscription: Get a list of metric alert rules in a specific subscription.
  • 更新:更新指标警报规则。Update: Update a metric alert rule.
  • 删除:删除指标警报规则。Delete: Delete a metric alert rule.

后续步骤Next steps