你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

将 Azure Monitor Application Insights 智能检测迁移到警报(预览版)

本文介绍将 Application Insights 智能检测迁移到警报的过程。 迁移时会为各种智能检测模块创建警报规则。 可以像管理和配置任何其他 Azure Monitor 预警规则一样管理和配置这些规则。 还可以为这些规则配置操作组,以获得多种方法来针对新的检测执行操作或触发通知。

迁移到警报的好处

通过迁移,智能检测现在支持利用 Azure Monitor 警报的完整功能,其中包括:

  • 适用于所有检测器的丰富通知选项:使用操作组可以配置触发警报时触发的多种类型的通知和操作。 可以按照电子邮件、短信、语音呼叫或推送通知配置通知。 可以配置多种操作,例如调用安全的 Webhook、逻辑应用和自动化 Runbook。 操作组支持配置一次操作,然后跨多个警报规则使用它们,从而实现进一步的大规模管理。
  • 大规模管理:智能检测警报使用 Azure Monitor 警报体验和 API。
  • 基于规则的通知抑制:使用操作规则在任何 Azure 资源管理器范围(例如 Azure 订阅、资源组或目标资源)内定义或抑制操作。 筛选器有助于缩小要处理的特定警报实例子集的范围。

迁移的智能检测功能

迁移 Application Insights 资源时,会创建一组新的预警规则。 系统会针对每个迁移的智能检测功能创建一个规则。 下表将迁移前的智能检测功能映射到迁移后的预警规则。

智能检测规则名称 (1) 警报规则名称 (2)
服务器响应降级 响应延迟降低 - <Application Insights 资源名称>
依赖项持续时间减少 依赖项延迟降低 - <Application Insights 资源名称>
跟踪严重性比下降(预览) 跟踪严重性降低 - <Application Insights 资源名称>
异常卷的异常增加(预览) 异常 - <Application Insights 资源名称>
检测到潜在的内存泄漏(预览) 潜在内存泄漏 - <Application Insights 资源名称>
页面加载慢 不再支持 (3)
服务器响应慢 不再支持 (3)
依赖项持续时间长 不再支持 (3)
检测到潜在的安全问题(预览) 不再支持 (3)
每日数据量中异常增加(预览) 不再支持 (3)

(1) 出现在智能检测“设置”窗格中的规则的名称。
(2) 迁移后的新预警规则的名称。
(3) 这些智能检测功能不会转换为警报,因为使用率较低而且检测效果需要重新评估。 完成迁移后,此资源将不再支持这些检测器。

注意

故障异常智能检测器已作为预警规则创建,不需要迁移。 本文不予讨论。

迁移不会更改智能检测的算法设计和行为。 更改之前和之后预期具有相同的检测性能。

需要单独将迁移应用到每个 Application Insights 资源。 对于未显式迁移的资源,智能检测将继续像以前一样工作。

新智能检测警报规则的操作组配置

在迁移过程中,系统会为每个新警报规则自动配置一个操作组。 迁移可以为每个规则分配默认操作组。 默认操作组根据迁移前的规则通知进行配置:

  • 如果智能检测规则配置了默认电子邮件或未配置通知,则新预警规则将配置名为“Application Insights 智能检测”的操作组。

    • 如果迁移工具找到使用该名称的现有操作组,它会将新的警报规则链接到该操作组。
    • 否则,它会创建使用该名称的新操作组。 新的组是为“向 Azure 资源管理器角色发送电子邮件”操作配置的,会将通知发送到 Azure 资源管理器监视参与者和监视读取者用户。
  • 如果在迁移之前更改了默认电子邮件通知,则会创建一个名为“Application Insights 智能检测 <n>”的操作组,并会创建一个向之前配置的电子邮件地址发送通知的电子邮件操作。

选择将为所有新警报规则配置的现有操作组,而不使用默认操作组。

执行智能检测迁移过程

请使用 Azure 门户、Azure CLI 或 Azure 资源管理器模板(ARM 模板)来执行迁移。

使用 Azure 门户迁移智能检测

若要迁移资源中的智能检测,请执行以下操作:

  1. 在 Application Insights 资源中的“调查”标题下,选择“智能检测”。

  2. 选择名为“将智能检测迁移到警报(预览版)”的横幅。 此时会显示迁移对话框。

    Screenshot that shows the Smart Detection feed banner.

  3. 选择“迁移此订阅中的所有 Application Insights 资源”选项。 或者,如果只想迁移当前所在的资源,则可以清除该选项。

    注意

    选择此选项会影响所有尚未迁移的现有 Application Insights 资源。 只要迁移到警报处于预览状态,新的 Application Insights 资源仍将使用非警报智能检测创建。

  4. 选择要为新的警报规则配置的操作组。 你可以按照说明使用默认操作组,也可以使用现有操作组之一。

  5. 选择“迁移”以启动迁移过程。

    Screenshot that shows the Smart Detection migration dialog.

迁移后,会为 Application Insight 资源创建新的预警规则,如前所述。

使用 Azure CLI 迁移智能检测

使用以下 Azure CLI 命令启动智能检测迁移。 如上文所述,该命令会触发预配置的迁移过程。

az rest --method POST --uri /subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/migrateFromSmartDetection?api-version=2021-01-01-preview --body @body.txt

若要迁移单个 Application Insights 资源,body.txt 应包括:

{
      "scope": [
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}"
      ],
      "actionGroupCreationPolicy" : "{Auto/Custom}",
      "customActionGroupName" : "{actionGroupName}"           
}

若要迁移订阅中的所有 Application Insights 资源,body.txt 应包括:

{
      "scope": [
	"/subscriptions/{subscriptionId} "
      ],
      "actionGroupCreationPolicy" : "{Auto/Custom}",
      "customActionGroupName" : "{actionGroupName}"           
}

ActionGroupCreationPolicy 参数选择用于将智能检测规则中的电子邮件设置迁移到操作组的策略。 允许的值包括:

  • 自动:使用本文档所述的默认操作组。
  • 自定义:使用 customActionGroupName 中指定的操作组创建所有预警规则。
  • <空白> - 如果未指定 ActionGroupCreationPolicy,则使用 Auto 策略。

使用 ARM 模板迁移智能检测

可以通过使用 ARM 模板,为特定的 Application Insights 资源触发从智能检测到警报的迁移。 若要使用此方法,需要执行以下操作:

  • 为每个受支持的检测器创建智能检测预警规则。
  • 修改 Application Insight 属性以指示迁移已完成。

使用此方法,你可以控制要创建的预警规则、定义自己的预警规则名称和说明,以及为每个规则选择所需的任何操作组。

为此,请使用以下模板。 根据需要编辑它们,以提供你的订阅 ID 和 Application Insights 资源名称。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
	"parameters": {
		"applicationInsightsResourceName": {
			"type": "string"
		},
		"actionGroupName": {
			"type": "string",
			"defaultValue": "Application Insights Smart Detection"
		},
		"actionGroupResourceGroup": {
			"type": "string",
			"defaultValue": "[resourceGroup().Name]"
		}
	},
	"variables": {
		"applicationInsightsResourceId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',resourceGroup().Name,'/providers/microsoft.insights/components/',parameters('applicationInsightsResourceName'))]",
		"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',parameters('actionGroupResourceGroup'),'/providers/microsoft.insights/ActionGroups/',parameters('actionGroupName'))]",
		"requestPerformanceDegradationDetectorRuleName": "[concat('Response Latency Degradation - ', parameters('applicationInsightsResourceName'))]",
		"dependencyPerformanceDegradationDetectorRuleName": "[concat('Dependency Latency Degradation - ', parameters('applicationInsightsResourceName'))]",
		"traceSeverityDetectorRuleName": "[concat('Trace Severity Degradation - ', parameters('applicationInsightsResourceName'))]",
		"exceptionVolumeChangedDetectorRuleName": "[concat('Exception Anomalies - ', parameters('applicationInsightsResourceName'))]",
		"memoryLeakRuleName": "[concat('Potential Memory Leak - ', parameters('applicationInsightsResourceName'))]"
	},
	"resources": [
		{
			"name": "[variables('requestPerformanceDegradationDetectorRuleName')]",
			"type": "Microsoft.AlertsManagement/smartdetectoralertrules",
			"location": "global",
			"apiVersion": "2019-03-01",
			"properties": {
				"description": "Response Latency Degradation notifies you of an unusual increase in latency in your app response to requests.",
				"state": "Enabled",
				"severity": "Sev3",
				"frequency": "PT24H",
				"detector": {
					"id": "RequestPerformanceDegradationDetector"
				},
				"scope": [
					"[variables('applicationInsightsResourceId')]"
				],
				"actionGroups": {	
					"groupIds": [
						"[variables('actionGroupId')]"
					]
				}
			}
		},
		{
			"name": "[variables('dependencyPerformanceDegradationDetectorRuleName')]",
			"type": "Microsoft.AlertsManagement/smartdetectoralertrules",
			"location": "global",
			"apiVersion": "2019-03-01",
			"properties": {
				"description": "Dependency Latency Degradation notifies you of an unusual increase in response by a dependency your app is calling (e.g. REST API or database)",
				"state": "Enabled",
				"severity": "Sev3",
				"frequency": "PT24H",
				"detector": {
					"id": "DependencyPerformanceDegradationDetector"
				},
				"scope": [
					"[variables('applicationInsightsResourceId')]"
				],
				"actionGroups": {
					"groupIds": [
						"[variables('actionGroupId')]"
					]
				}
			}
		},
		{
			"name": "[variables('traceSeverityDetectorRuleName')]",
			"type": "Microsoft.AlertsManagement/smartdetectoralertrules",
			"location": "global",
			"apiVersion": "2019-03-01",
			"properties": {
				"description": "Trace Severity Degradation notifies you of an unusual increase in the severity of the traces generated by your app.",
				"state": "Enabled",
				"severity": "Sev3",
				"frequency": "PT24H",
				"detector": {
					"id": "TraceSeverityDetector"
				},
				"scope": [
					"[variables('applicationInsightsResourceId')]"
				],
				"actionGroups": {
					"groupIds": [
						"[variables('actionGroupId')]"
					]
				}
			}
		},
		{
			"name": "[variables('exceptionVolumeChangedDetectorRuleName')]",
			"type": "Microsoft.AlertsManagement/smartdetectoralertrules",
			"location": "global",
			"apiVersion": "2019-03-01",
			"properties": {
				"description": "Exception Anomalies notifies you of an unusual rise in the rate of exceptions thrown by your app.",
				"state": "Enabled",
				"severity": "Sev3",
				"frequency": "PT24H",
				"detector": {
					"id": "ExceptionVolumeChangedDetector"
				},
				"scope": [
					"[variables('applicationInsightsResourceId')]"
				],
				"actionGroups": {
					"groupIds": [
						"[variables('actionGroupId')]"
					]
				}
			}
		},
		{
			"name": "[variables('memoryLeakRuleName')]",
			"type": "Microsoft.AlertsManagement/smartdetectoralertrules",
			"location": "global",
			"apiVersion": "2019-03-01",
			"properties": {
				"description": "Potential Memory Leak notifies you of increased memory consumption pattern by your app which may indicate a potential memory leak.",
				"state": "Enabled",
				"severity": "Sev3",
				"frequency": "PT24H",
				"detector": {
					"id": "MemoryLeakDetector"
				},
				"scope": [
					"[variables('applicationInsightsResourceId')]"
				],
				"actionGroups": {
					"groupIds": [
						"[variables('actionGroupId')]"
					]
				}
			}
		},
		{
			"name": "[concat(parameters('applicationInsightsResourceName'),'/migrationToAlertRulesCompleted')]",
			"type": "Microsoft.Insights/components/ProactiveDetectionConfigs",
			"location": "[resourceGroup().location]",
			"apiVersion": "2018-05-01-preview",
			"properties": {
				"name": "migrationToAlertRulesCompleted",
				"sendEmailsToSubscriptionOwners": false,
				"customEmails": [],
				"enabled": true
			},
			"dependsOn": [
				"[resourceId('Microsoft.AlertsManagement/smartdetectoralertrules', variables('requestPerformanceDegradationDetectorRuleName'))]",
				"[resourceId('Microsoft.AlertsManagement/smartdetectoralertrules', variables('dependencyPerformanceDegradationDetectorRuleName'))]",
				"[resourceId('Microsoft.AlertsManagement/smartdetectoralertrules', variables('traceSeverityDetectorRuleName'))]",
				"[resourceId('Microsoft.AlertsManagement/smartdetectoralertrules', variables('exceptionVolumeChangedDetectorRuleName'))]",
				"[resourceId('Microsoft.AlertsManagement/smartdetectoralertrules', variables('memoryLeakRuleName'))]"
			]
		}
	]
}

在迁移后查看警报

迁移后,可以通过在 Application Insights 资源中选择“警报”条目来查看智能检测警报。 选择“智能检测器”作为“信号类型”,以仅筛选并显示智能检测警报。 可以选择警报来查看其检测详细信息。

Screenshot that shows smart detection alerts.

仍可在 Application Insights 资源的智能检测源中查看可用的检测。

Screenshot that shows the Smart Detection feed.

在迁移后管理智能检测预警规则设置

使用 Azure 门户或 ARM 模板在迁移后管理智能检测预警规则设置。

使用 Azure 门户管理预警规则设置

迁移完成后,可以像访问为资源定义的其他预警规则一样访问新的智能检测预警规则。

  1. 在 Application Insights 资源中的“监视”标题下,选择“警报”。

    Screenshot that shows the Alerts menu.

  2. 选择“管理警报规则”。

    Screenshot that shows Manage alert rules.

  3. 选择“智能检测器”作为“信号类型”,以筛选并显示智能检测预警规则。

    Screenshot that shows smart detection rules.

启用或禁用智能检测预警规则

智能检测预警规则可以通过门户 UI 或编程方式启用或禁用,就像任何其他预警规则一样。

如果在迁移之前禁用了特定的智能检测规则,则新预警规则也将被禁用。

为预警规则配置操作组

可以为新的智能检测预警规则创建和管理操作组,就像为任何其他 Azure Monitor 预警规则所做的那样。

使用 ARM 模板管理预警规则设置

完成迁移后,可以使用 ARM 模板为智能检测预警规则设置配置设置。

注意

完成迁移后,必须使用智能检测预警规则模板配置智能检测设置。 再也无法使用 Application Insights 资源管理器模板对其进行配置。

此 ARM 模板示例演示了如何在严重性为 2 的“Enabled”状态下配置“Response Latency Degradation”预警规则。

  • 智能检测是一项全局服务,因此规则位置是在 global 位置中创建的。

  • id 属性应随配置的特定检测器而变。 值必须是以下项之一:

    • FailureAnomaliesDetector
    • RequestPerformanceDegradationDetector
    • DependencyPerformanceDegradationDetector
    • ExceptionVolumeChangedDetector
    • TraceSeverityDetector
    • MemoryLeakDetector
{
    "$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": "Response Latency Degradation - my-app",
            "location": "global", 
            "properties": {
                  "description": "Response Latency Degradation notifies you of an unusual increase in latency in your app response to requests.",
                  "state": "Enabled",
                  "severity": "2",
                  "frequency": "PT24H",
                  "detector": {
                  "id": "RequestPerformanceDegradationDetector"
                  },
                  "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"]
                  }
            }
        }
    ]
}

后续步骤