使用 Azure 资源管理器模板管理 Application Insights 智能检测规则Manage Application Insights smart detection rules using Azure Resource Manager templates

可以使用 Azure 资源管理器模板来管理和配置 Application Insights 中的智能检测规则。Smart detection rules in Application Insights can be managed and configured using Azure Resource Manager templates. 使用 Azure 资源管理器自动化部署新的 Application Insights 资源或修改现有资源的设置时,可以使用此方法。This method can be used when deploying new Application Insights resources with Azure Resource Manager automation, or for modifying the settings of existing resources.

智能检测规则配置Smart detection rule configuration

可以配置智能检测规则的以下设置:You can configure the following settings for a smart detection rule:

  • 是否已启用该规则(默认值为 true。)If the rule is enabled (the default is true.)
  • 发现检测时是否应向与订阅的监视读者监视参与者角色关联的用户发送电子邮件(默认值为 true)。If emails should be sent to users associated to the subscription’s Monitoring Reader and Monitoring Contributor roles when a detection is found (the default is true.)
  • 找到检测项时,应收到通知的其他任何电子邮件收件人。Any additional email recipients who should get a notification when a detection is found.
    • 电子邮件配置不适用于标记为“预览”的智能检测规则 。Email configuration is not available for Smart Detection rules marked as preview.

为了让用户通过 Azure 资源管理器配置规则设置,智能检测规则配置现已在 Application Insights 资源中提供一个名为 ProactiveDetectionConfigs 的内部资源。To allow configuring the rule settings via Azure Resource Manager, the smart detection rule configuration is now available as an inner resource within the Application Insights resource, named ProactiveDetectionConfigs. 为了提供最大的灵活性,可为每个智能检测规则配置独特的通知设置。For maximal flexibility, each smart detection rule can be configured with unique notification settings.

示例Examples

以下几个示例演示如何使用 Azure 资源管理器模板配置智能检测规则的设置。Below are a few examples showing how to configure the settings of smart detection rules using Azure Resource Manager templates. 在所有示例中,Application Insights 资源名为 myApplication,“‘依赖项持续时间长’智能检测规则”的内部名称为 longdependencydurationAll samples refer to an Application Insights resource named “myApplication”, and to the "long dependency duration smart detection rule", which is internally named “longdependencyduration”. 请务必替换 Application Insights 资源名称,并指定相关的智能检测规则内部名称。Make sure to replace the Application Insights resource name, and to specify the relevant smart detection rule internal name. 在下表中查看每个智能检测规则的对应内部 Azure 资源管理器名称列表。Check the table below for a list of the corresponding internal Azure Resource Manager names for each smart detection rule.

禁用智能检测规则Disable a smart detection rule

{
      "apiVersion": "2018-05-01-preview",
      "name": "myApplication",
      "type": "Microsoft.Insights/components",
      "location": "[resourceGroup().location]",
      "properties": {
        "ApplicationId": "myApplication"
      },
      "resources": [
        {
          "apiVersion": "2018-05-01-preview",
          "name": "longdependencyduration",
          "type": "ProactiveDetectionConfigs",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Insights/components', 'myApplication')]"
          ],
          "properties": {
            "name": "longdependencyduration",
            "sendEmailsToSubscriptionOwners": true,
            "customEmails": [],
            "enabled": false
          }
        }
      ]
    }

禁用发送有关某个智能检测规则的电子邮件通知Disable sending email notifications for a smart detection rule

{
      "apiVersion": "2018-05-01-preview",
      "name": "myApplication",
      "type": "Microsoft.Insights/components",
      "location": "[resourceGroup().location]",
      "properties": {
        "ApplicationId": "myApplication"
      },
      "resources": [
        {
          "apiVersion": "2018-05-01-preview",
          "name": "longdependencyduration",
          "type": "ProactiveDetectionConfigs",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Insights/components', 'myApplication')]"
          ],
          "properties": {
            "name": "longdependencyduration",
            "sendEmailsToSubscriptionOwners": false,
            "customEmails": [],
            "enabled": true
          }
        }
      ]
    }

为智能检测规则添加更多的电子邮件收件人Add additional email recipients for a smart detection rule

{
      "apiVersion": "2018-05-01-preview",
      "name": "myApplication",
      "type": "Microsoft.Insights/components",
      "location": "[resourceGroup().location]",
      "properties": {
        "ApplicationId": "myApplication"
      },
      "resources": [
        {
          "apiVersion": "2018-05-01-preview",
          "name": "longdependencyduration",
          "type": "ProactiveDetectionConfigs",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Insights/components', 'myApplication')]"
          ],
          "properties": {
            "name": "longdependencyduration",
            "sendEmailsToSubscriptionOwners": true,
            "customEmails": ['alice@contoso.com', 'bob@contoso.com'],
            "enabled": true
          }
        }
      ]
    }

故障异常 v2(非经典)警报规则Failure Anomalies v2 (non-classic) alert rule

此 Azure 资源管理器模板演示如何配置严重性为 2 的故障异常 v2 警报规则。This Azure Resource Manager template demonstrates configuring a Failure Anomalies v2 alert rule with a severity of 2. 此新版本的故障异常警报规则是新 Azure 警报平台的一部分,它取代了在经典警报停用流程中停用的经典版本。This new version of the Failure Anomalies alert rule is part of the new Azure alerting platform, and replaces the classic version that is being retired as part of the classic alerts retirement process.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "type": "microsoft.alertsmanagement/smartdetectoralertrules",
            "apiVersion": "2019-03-01",
            "name": "Failure Anomalies - my-app",
            "properties": {
                  "description": "Detects a spike in the failure rate of requests or dependencies",
                  "state": "Enabled",
                  "severity": "2",
                  "frequency": "PT1M",
                  "detector": {
                  "id": "FailureAnomaliesDetector"
                  },
                  "scope": ["/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/MyResourceGroup/providers/microsoft.insights/components/my-app"],
                  "actionGroups": {
                        "groupIds": ["/subscriptions/00000000-1111-2222-3333-444444444444/resourcegroups/MyResourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup"]
                  }
            }
        }
    ]
}

Note

此 Azure 资源管理器模板对于故障异常 v2 警报规则来说是唯一的,并且不同于本文中所述的其他经典智能检测规则。This Azure Resource Manager template is unique to the Failure Anomalies v2 alert rule and is different from the other classic Smart Detection rules described in this article.

智能检测规则名称Smart detection rule names

下表列出了门户中显示的智能检测规则名称,以及应在 Azure 资源管理器模板中为这些规则使用的内部名称。Below is a table of smart detection rule names as they appear in the portal, along with their internal names, that should be used in the Azure Resource Manager template.

Note

标记为“预览”的智能检测规则不支持电子邮件通知。Smart detection rules marked as preview don’t support email notifications. 因此,只能为这些规则设置已启用的属性。Therefore, you can only set the enabled property for these rules.

Azure 门户规则名称Azure portal rule name 内部名称Internal name
页面加载慢Slow page load time slowpageloadtimeslowpageloadtime
服务器响应慢Slow server response time slowserverresponsetimeslowserverresponsetime
依赖项持续时间长Long dependency duration longdependencydurationlongdependencyduration
服务器响应降级Degradation in server response time degradationinserverresponsetimedegradationinserverresponsetime
依赖项持续时间减少Degradation in dependency duration degradationindependencydurationdegradationindependencyduration
跟踪严重性比下降(预览)Degradation in trace severity ratio (preview) extension_traceseveritydetectorextension_traceseveritydetector
异常卷的异常增加(预览)Abnormal rise in exception volume (preview) extension_exceptionchangeextensionextension_exceptionchangeextension
检测到潜在的内存泄漏(预览)Potential memory leak detected (preview) extension_memoryleakextensionextension_memoryleakextension
检测到潜在的安全问题(预览)Potential security issue detected (preview) extension_securityextensionspackageextension_securityextensionspackage
每日数据量中异常增加(预览)Abnormal rise in daily data volume (preview) extension_billingdatavolumedailyspikeextensionextension_billingdatavolumedailyspikeextension

后续步骤Next Steps

了解有关自动检测的详细信息:Learn more about automatically detecting: