使用 Azure 監視器建立、檢視及管理計量警示Create, view, and manage metric alerts using Azure Monitor

想在其中一個計量超過閾值時收到通知,可以利用 Azure 監視器中的計量警示。Metric alerts in Azure Monitor provide a way to get notified when one of your metrics cross 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 Resource Manager 範本,來建立計量警示規則。You can also create metric alert rules using Azure Resource Manager templates which is 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. (選擇性) 藉由調整 [期限] 和 [彙總] 來精簡計量。Optionally, refine the metric by adjusting Period and Aggregation. 如果計量具有維度,您將會看到顯示 [維度] 資料表。If the metric has dimensions, you will see Dimensions table presented. 為每個維度選取一或多個值。Select one or more values per dimension. 計量警示會對所選值的所有組合評估其條件。The metric alert will run evaluate the condition for all combinations of values selected. 深入了解對多維度計量發出警示的運作方式Learn more about how alerting on multi-dimensional metrics works. Select * 也可以讓您選取任何維度。You can also Select * for any of the dimensions. Select * 會將選擇動態擴充至維度的所有目前與未來值。Select * will dynamically scale the selection to all current and future values for a dimension.

  8. 您會看到過去 6 小時的計量圖表。You will see a chart for the metric for the last 6 hours. 定義警示參數;[條件類型] 、[頻率] 、[運算子] 與 [閾值] 或 [敏感度] ,這可決定計量警示規則的評估邏輯。Define the alert parameters; Condition Type, Frequency, Operator and Threshold or Sensitivity, this will determine the logic which the metric alert rule will evaluate. 深入了解動態閾值條件類型和敏感度選項Learn more about Dynamic Thresholds condition type and sensitivity options.

  9. 使用靜態閾值時,計量圖表可以協助判斷哪些是合理的閾值。If you are using a static threshold, the metric chart can help determine what might be a reasonable threshold. 使用動態臨界值時,計量圖表會顯示以最近使用的資料為基礎的計算臨界值。If you are using a Dynamic Thresholds, the metric chart will display the calculated thresholds based on recent data.

  10. 按一下 [完成] Click Done

  11. (選擇性) 如果您想要監視複雜的警示規則,請新增另一個準則。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.

  12. 填寫 [警示詳細資料] ,例如 [警示規則名稱] 、[描述] 與 [嚴重性] Fill in Alert details like Alert Rule Name, Description and Severity

  13. 透過選取現有動作群組或建立新的動作群組,將動作群組新增至警示。Add an action group to the alert either by selecting an existing action group or creating a new action group.

  14. 按一下 [完成] 以儲存計量警示規則。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 Shell] 。Go 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. 您可以使用規則的名稱或資源識別碼,來查看特定計量警示規則的詳細資料。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}
    

後續步驟Next steps