將 Azure 監視器 Application Insights 智慧偵測遷移至警示 (預覽版)

本文說明將 Application Insights 智慧偵測移轉至警示的流程。 遷移會建立不同智慧偵測模組的警示規則。 您可以像管理和設定其他 Azure 監視器一樣來管理和設定這些規則。 您也可以設定這些規則的動作群組,以便在新偵測時獲得多種動作或通知方法。

移轉至警示的優點

透過移轉,智慧偵測現在可讓您利用 Azure 監視器警示的完整功能,包括:

  • 所有偵測器的豐富通知選項:使用 [動作群組] 可設定在引發警示時會觸發的多個類型的通知和動作。 可以透過電子郵件、簡訊、語音通話或推播通知來設定通知。 可以設定多種動作,例如呼叫安全的 Webhook、邏輯應用程式和自動化 Runbook。 動作群組讓您設定一次動作就能在多個警示規則之間使用這些動作,進一步提供大規模的管理。
  • 大規模管理:智慧偵測警示使用 Azure 監視器警示體驗和 API。
  • 以規則為基礎的通知隱藏:使用 [動作規則] 在任何 Azure Resource Manager 範圍 (例如,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 Resource Manager 角色」動作所設定的新群組,會將通知傳送給 Azure Resource Manager 監視參與者和監視讀者使用者。
  • 如果在移轉之前變更了預設電子郵件通知,則會建立名為「Application Insights 智慧偵測 <n>」的動作群組,並建立電子郵件動作,將通知傳送至先前設定的電子郵件地址。

您不需要使用預設動作群組,而是選取會針對所有新警示規則設定的現有動作群組。

執行智慧偵測移轉程序

使用 Azure 入口網站、Azure CLI 或 Azure Resource Manager 範本 (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 屬性以表示移轉已完成。

使用此方法,您可以控制要建立的警示規則、定義自己的警示規則名稱和描述,以及為每個規則選取所需的任何動作群組。

為了此目的,請使用下列範本。 視需要編輯這些範本,以提供您的訂用帳戶識別碼和 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 監視器警示規則所作的一樣。

使用 ARM 範本管理警示規則設定

移轉完成後,可以使用 ARM 範本來配置設定智慧偵測警示規則設定。

注意

移轉完成後,必須使用智慧偵測警示規則範本設定智慧偵測設定。 無法再使用 Application Insights Resource Manager 範本來進行設定。

此 ARM 範本示範了如何在嚴重性為 2Enabled 狀態下設定 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"]
                  }
            }
        }
    ]
}

下一步