Application Insights 與 Log Analytics 整合,並將遙測數據傳送至常見的 Log Analytics 工作區。 此設定提供對 Log Analytics 功能的完整存取權,將記錄合併到一個位置,並允許統一的 Azure 角色型存取控制,進而消除進行跨應用程式/工作區查詢的需要。
增強的功能包括:
本文說明如何建立及設定Application Insights資源。 除了 Application Insights 資源本身,您還可以新增各種設定,例如設定 每日 上限和 定價方案。 您也可以建立 可用性測試、設定 計量警示,以及使用 Azure Resource Manager 將程式自動化。
備註
工作區型 Application Insights 資源的資料內嵌和保留會透過資料所在的 Log Analytics 工作區來計費。 若要深入瞭解計費,請參閱 Azure 監視器記錄定價詳細數據。
先決條件
- 有效的 Azure 訂用帳戶。
- 建立資源所需的許可權。
其他需求
若要存取 Application Insights Azure CLI 命令,您必須先執行:
az extension add -n application-insights
如果您未執行 az extension add
命令,則會看到錯誤訊息,指出 az : ERROR: az monitor: 'app-insights' is not in the 'az monitor' command group. See 'az monitor --help'
。
您可以透過 Azure CLI、Azure PowerShell 和 Azure 入口網站來部署 Bicep 範本。 檢查各個標籤頁以了解額外要求。
您可以透過 Azure CLI、Azure PowerShell 和 Azure 入口網站來部署 ARM 範本。 查看個別索引標籤可了解其他需求。
建立 Application Insights 資源
- 登入 Azure 入口網站。
- 選擇 "建立資源"。
- 開啟 [監視與診斷] 類別,然後選取 [Application Insights]。
- 輸入所有相關信息,然後 檢閱 + 建立 Application Insights 資源。
附註
如果您在資源建立期間未連線到現有的Log Analytics工作區,系統會自動建立新的Log Analytics資源與Application Insights 資源。
建立資源之後,您可以在 [Application Insights 概 觀] 窗格中找到對應的工作區資訊。
選取藍色連結文字,移至相關聯的 Log Analytics 工作區,您可以在其中利用新的整合工作區查詢環境。
附註
我們仍會為您的 Application Insights 傳統資源查詢、活頁簿和記錄型警示提供完整的回溯相容性。 若要查詢或檢視新的工作區型資料表結構或結構描述,您必須先移至 Log Analytics 工作區。 選取 [Application Insights] 窗格中的 [記錄 (分析)],可讓您存取傳統 Application Insights 查詢體驗。
若要建立工作區型 Application Insights 資源,則需要 Log Analytics 工作區。 如果您還沒有帳戶,您可以使用下列 Azure CLI 命令來建立一個。
預留位置:<resource-group-name>
、<log-analytics-workspace-name>
、<azure-region-name>
az monitor log-analytics workspace create --resource-group <resource-group-name> --workspace-name <log-analytics-workspace-name> --location <azure-region-name>
若要建立 Application Insights 資源,請在終端機中執行下列 Azure CLI 命令。
佔位元:<application-insights-resource-name>
、<azure-region-name>
、<resource-group-name>
、<log-analytics-workspace-name>
az monitor app-insights component create --app <application-insights-resource-name> --location <azure-region-name> --resource-group <resource-group-name> --workspace <log-analytics-workspace-name>
如需使用 Azure CLI 建立 Application Insights 資源和 Log Analytics 工作區的詳細資訊,請參閱 Application Insights 和 Log Analytics的 Azure CLI 檔。
若要建立工作區型 Application Insights 資源,則需要 Log Analytics 工作區。 如果您還沒有帳戶,您可以使用下列 Azure PowerShell 命令來建立一個。
預留位置:<resource-group-name>
、<log-analytics-workspace-name>
、<azure-region-name>
New-AzOperationalInsightsWorkspace -ResourceGroupName <resource-group-name> -Name <log-analytics-workspace-name> -Location <azure-region-name>
若要建立 Application Insights 資源,請在終端機中執行下列 Azure PowerShell 命令。
佔位元:<resource-group-name>
、<application-insights-resource-name>
、<azure-region-name>
、<subscription-id>
、<log-analytics-workspace-name>
New-AzApplicationInsights -ResourceGroupName <resource-group-name> -Name <application-insights-resource-name> -Location <azure-region-name> -WorkspaceResourceId /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>
如需使用 Azure PowerShell 建立 Application Insights 資源和 Log Analytics 工作區的詳細資訊,請參閱 Application Insights 和 Log Analytics的 Azure PowerShell 檔。
若要建立工作區型 Application Insights 資源,則需要 Log Analytics 工作區。 如果您還沒有,您可以使用下列 REST API 呼叫來建立一個。
佔位元:<subscription-id>
、<resource-group-name>
、<log-analytics-workspace-name>
、<access-token>
、<azure-region-name>
PUT https://management.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>?api-version=2023-09-01
Authorization: Bearer <access-token>
Content-Type: application/json
{
"location": "<azure-region-name>"
}
若要使用 REST API 建立 Application Insights 資源,請使用下列要求。
佔位元:<subscription-id>
、<resource-group-name>
、<application-insights-resource-name>
、<access-token>
、<application-type>
、<azure-region-name>
、<log-analytics-workspace-name>
PUT https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Insights/components/<application-insights-resource-name>?api-version=2020-02-02
Authorization: Bearer <access-token>
Content-Type: application/json
{
"kind": "<application-type>",
"location": "<azure-region-name>",
"properties": {
"Application_Type": "<application-type>",
"WorkspaceResourceId": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>"
}
}
如需使用 REST API 建立 Application Insights 資源和 Log Analytics 工作區的詳細資訊,請參閱 Application Insights 和 Log Analytics的 REST API 檔。
以下說明如何使用 Bicep 範本建立新的 Application Insights 資源。
建立範本
建立新的 .bicep 檔案(例如 my-template.bicep),將下列內容複製到其中:
param name string
param type string
param regionId string
param requestSource string
param workspaceResourceId string
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: name
location: regionId
tags: tagsArray
kind: 'other'
properties: {
Application_Type: type
Request_Source: requestSource
WorkspaceResourceId: workspaceResourceId
}
}
建立參數檔案
建立新的 .bicepparam 檔案(例如 my-parameters.bicepparam),將下列內容複製到其中,並以您的特定值取代佔位符 <application-insights-resource-name>
、<application-type>
、、<azure-region-name>
、 <subscription-id>
<resource-group-name>
和 <log-analytics-workspace-name>
:
using 'my-template.bicep'
param name string = '<application-insights-resource-name>'
param type string = '<application-type>'
param regionId string = '<azure-region-name>'
param requestSource string = 'CustomDeployment'
param workspaceResourceId string = '/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<log-analytics-workspace-name>'
使用範本建立新的 Application Insights 資源
在 PowerShell 中,使用 $Connect-AzAccount
登入至 Azure。
使用 Set-AzContext "<subscription ID>"
將內容設定至訂用帳戶。
執行新部署來建立新的 Application Insights 資源:
New-AzResourceGroupDeployment -ResourceGroupName <your-resource-group> -TemplateFile my-template.bicep -TemplateParameterFile my-parameters.bicepparam
-ResourceGroupName
是您要在其中建立新資源的群組。
-TemplateFile
必須出現在自訂參數之前。
-TemplateParameterFile
是參數檔案的名稱。
您可以新增其他參數。 您可以在樣本的參數區段中找到其描述。
以下說明如何使用ARM範本建立新的Application Insights資源。
建立範本
建立新的 .json 檔案(例如 ,my-template.json),並將下列內容複製到其中:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"metadata": {
"description": "Name of Application Insights resource."
}
},
"type": {
"type": "string",
"metadata": {
"description": "Type of app you are deploying. This field is for legacy reasons and will not impact the type of Application Insights resource you deploy."
}
},
"regionId": {
"type": "string",
"metadata": {
"description": "Which Azure region to deploy the resource to. This must be a valid Azure regionId."
}
},
"tagsArray": {
"type": "object",
"metadata": {
"description": "See documentation on tags: https://learn.microsoft.com/azure/azure-resource-manager/management/tag-resources."
}
},
"requestSource": {
"type": "string",
"metadata": {
"description": "Source of Azure Resource Manager deployment"
}
},
"workspaceResourceId": {
"type": "string",
"metadata": {
"description": "Log Analytics workspace ID to associate with your Application Insights resource."
}
}
},
"resources": [
{
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02",
"name": "[parameters('name')]",
"location": "[parameters('regionId')]",
"tags": "[parameters('tagsArray')]",
"kind": "other",
"properties": {
"Application_Type": "[parameters('type')]",
"Request_Source": "[parameters('requestSource')]",
"WorkspaceResourceId": "[parameters('workspaceResourceId')]"
}
}
]
}
附註
如需資源屬性的詳細資訊,請參閱屬性值。
並不會使用 Flow_Type
和 Request_Source
,但這兩項會包含在此範例中以確保完整性。
建立參數檔案
建立新的 .json 檔案(例如 ,my-parameters.json),將下列內容複製到其中,並以您的特定值取代佔位元 <application-insights-resource-name>
、 <application-type>
、、 <azure-region-name>
、 <subscription-id>
、 <resource-group-name>
和 <log-analytics-workspace-name>
:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "<application-insights-resource-name>"
},
"type": {
"value": "<application-type>"
},
"regionId": {
"value": "<azure-region-name>"
},
"tagsArray": {
"value": {}
},
"requestSource": {
"value": "CustomDeployment"
},
"workspaceResourceId": {
"value": "/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<log-analytics-workspace-name>"
}
}
}
使用範本建立新的 Application Insights 資源
在 PowerShell 中,使用 $Connect-AzAccount
登入至 Azure。
使用 Set-AzContext "<subscription ID>"
將內容設定至訂用帳戶。
執行新部署來建立新的 Application Insights 資源:
New-AzResourceGroupDeployment -ResourceGroupName <your-resource-group> -TemplateFile my-template.json -TemplateParameterFile my-parameters.json
-ResourceGroupName
是您要在其中建立新資源的群組。
-TemplateFile
必須出現在自訂參數之前。
-TemplateParameterFile
是參數檔案的名稱。
建立 Application Insights 資源之後,您可以設定監視。
取得連接字串
連接字串可識別您想要與遙測資料建立關聯的資源。 您也可以將其用來修改您資源將用作遙測目的地的端點。 您必須複製連接字串,並將其新增至應用程式的程式碼或新增至環境變數。
若要取得 Application Insights 資源的連接字串:
- 在 Azure 入口網站中開啟 Application Insights 資源。
- 在 [基本資訊] 區段中的 [概觀] 窗格中,尋找 [連接字串]。
- 如果您將滑鼠停留在連接字串上方,則會出現一個圖示,可讓您將它複製到剪貼簿。
若要取得連接字串,請在終端機中執行下列 Azure CLI 命令,並以您的特定值取代佔位元 <application-insights-resource-name>
和 <resource-group-name>
:
az monitor app-insights component show --app <application-insights-resource-name> --resource-group <resource-group-name> --query connectionString --output tsv
如需命令的詳細資訊 az monitor app-insights component show
,請參閱 Azure CLI 檔。
若要取得連接字串,請在終端機中執行下列 Azure PowerShell 命令,並將 佔位元 <resource-group-name>
取代 <application-insights-resource-name>
為您的特定值:
Get-AzApplicationInsights -ResourceGroupName <resource-group-name> -Name <application-insights-resource-name> | Select-Object -ExpandProperty ConnectionString
如需命令的詳細資訊 Get-AzApplicationInsights
,請參閱 Azure PowerShell 檔。
若要擷取 Application Insights 資源的詳細數據,請使用下列要求,並以您的特定值取代佔位元 <subscription-id>
、 <resource-group-name>
、 <application-insights-resource-name>
和 <access-token>
:
GET https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Insights/components/<application-insights-resource-name>?api-version=2015-05-01
Authorization: Bearer <access-token>
在 JSON 回應中尋找 properties.connectionString
欄位。
如需使用 REST API 擷取 Application Insights 資源相關信息的詳細資訊,請參閱 REST API 檔。
使用 OpenTelemetry 的應用程式監視
若要使用 OpenTelemetry 進行應用程式監視,您可以安裝適當的 Azure 監視器 OpenTelemetry Distro,並將連接字串指向您新建立的資源。
如需如何使用 OpenTelemetry 設定應用程式監視的資訊,請參閱語言專屬的下列檔:
自動檢測
針對 Azure Functions 和 Azure App Service 等監視服務,您可以先建立 Application Insights 資源,然後在啟用監視時指向它。 或者,您可以在啟用程序期間建立新的 Application Insights 資源。
修改相關聯的工作區
建立 Application Insights 資源之後,您可以修改相關聯的 Log Analytics 工作區。
在您的 Application Insights 資源中,選取 [屬性>變更工作區>Log Analytics 工作區]。
若要變更 Log Analytics 工作區,請在終端機中執行下列 Azure CLI 命令,並以您的特定值取代佔位元 <application-insights-resource-name>
元、 <resource-group-name>
和 <log-analytics-workspace-name>
:
az monitor app-insights component update --app <application-insights-resource-name> --resource-group <resource-group-name> --workspace <log-analytics-workspace-name>
如需命令的詳細資訊 az monitor app-insights component update
,請參閱 Azure CLI 檔。
若要變更 Log Analytics 工作區,請在終端機中執行下列 Azure PowerShell 命令,並以您的特定值取代佔位元 <resource-group-name>
、 <application-insights-resource-name>
、 <subscription-id>
和 <log-analytics-workspace-name>
:
Update-AzApplicationInsights -ResourceGroupName <resource-group-name> -Name <application-insights-resource-name> -WorkspaceResourceId /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>
如需命令的詳細資訊 Update-AzApplicationInsights
,請參閱 Azure PowerShell 檔。
若要使用 REST API 變更 Log Analytics 工作區,請使用下列要求,並以您的特定值取代佔位元 <subscription-id>
、 <resource-group-name>
、 <application-insights-resource-name>
、 <access-token>
、 <azure-region-name>
和 <log-analytics-workspace-name>
:
PATCH https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Insights/components/<application-insights-resource-name>?api-version=2020-02-02
Authorization: Bearer <access-token>
Content-Type: application/json
{
"location": "<azure-region-name>",
"properties": {
"WorkspaceResourceId": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>"
}
}
如需使用 REST API 修改相關聯工作區的詳細資訊,請參閱 REST API 檔。
若要變更 Log Analytics 工作區,請將下列程式代碼貼到您的範本中,並以您的特定值取代佔位元 <application-insights-resource-name>
、 <azure-region-name>
、 <application-type>
和 <log-analytics-workspace-name>
:
param workspaceResourceId string = '/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>'
resource appInsights 'Microsoft.Insights/components@2020-02-02-preview' = {
name: '<application-insights-resource-name>'
location: '<azure-region-name>'
properties: {
Application_Type: '<application-type>'
WorkspaceResourceId: workspaceResourceId
}
}
若要變更 Log Analytics 工作區,請將下列程式代碼貼到您的範本中,並以您的特定值取代佔位元 <application-insights-resource-name>
、 <azure-region-name>
、 <application-type>
和 <log-analytics-workspace-name>
:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02-preview",
"name": "<application-insights-resource-name>",
"location": "<azure-region-name>",
"properties": {
"Application_Type": "<application-type>",
"WorkspaceResourceId": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>"
}
}
]
}
匯出遙測
工作區型資源不支援傳統的連續匯出功能。 請改用 診斷設定。
在您的 Application Insights 資源中,選取 [ 診斷設定>][新增診斷設定]。
您可以選取要封存到記憶體帳戶的所有資料表或資料表子集。 您也可以串流至事件中樞。
若要使用診斷設定匯出遙測,請在終端機中執行下列 Azure CLI 命令,並以您的特定值取代佔位元 <diagnostic-setting-name>
、 <application-insights-resource-name>
、 <resource-group-name>
和 <storage-account-name>
:
az monitor diagnostic-settings create --name <diagnostic-setting-name> --resource <application-insights-resource-name> --resource-group <resource-group-name> --resource-type Microsoft.Insights/components --storage-account <storage-account-name>
這個範例命令會啟用診斷設定,並將 Application Insights 資源的所有記錄傳送至指定的記憶體帳戶。 若要同時傳送計量,請將 新增 --metrics '[{"category": "AllMetrics", "enabled": true}]'
至 命令。
如需命令的詳細資訊 az monitor diagnostic-settings create
,請參閱 Azure CLI 檔。
若要使用診斷設定匯出遙測,請在終端機中執行下列 Azure PowerShell 命令,並以您的特定值取代佔位元 <application-insights-resource-id>
元、 <diagnostic-setting-name>
和 <storage-account-id>
:
Set-AzDiagnosticSetting -ResourceId <application-insights-resource-id> -Name <diagnostic-setting-name> -StorageAccountId <storage-account-id> -Enabled $True
這個範例命令會啟用診斷設定,並將 Application Insights 資源的所有計量和記錄傳送至指定的記憶體帳戶。
如需命令的詳細資訊 Set-AzDiagnosticSetting
,請參閱 Azure PowerShell 檔。
若要使用診斷設定將遙測匯出至 Azure 記憶體帳戶,請使用下列要求,並以您的特定值取代佔位元 <subscription-id>
、 <resource-group-name>
、 <application-insights-resource-name>
、 <diagnostic-setting-name>
、 <access-token>
和 <storage-account-name>
:
PUT https://management.azure.com//subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>/providers/Microsoft.Insights/diagnosticSettings/<diagnostic-setting-name>?api-version=2021-05-01-preview
Authorization: Bearer <access-token>
Content-Type: application/json
{
"properties": {
"storageAccountId": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>",
"logs": [
{
"category": "AppRequests",
"enabled": true
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true
}
]
}
}
此範例呼叫會啟用診斷設定,並將 Application Insights 資源的所有計量和記錄傳送至指定的記憶體帳戶。
如需使用 REST API 建立診斷設定的詳細資訊,請參閱 REST API 檔。
若要使用診斷設定匯出遙測,請將下列程式代碼貼到您的範本中,並以您的特定值取代佔位元 <application-insights-resource-name>
、<azure-region-name>
、<application-type>
、<diagnostic-setting-name>
、 <subscription-id>
<resource-group>
和 <storage-account-name>
:
param appInsightsName string = '<application-insights-resource-name>'
param location string = '<azure-region-name>'
param applicationType string = '<application-type>'
param diagnosticSettingName string = '<diagnostic-setting-name>'
param storageAccountId string = '/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>'
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appInsightsName
location: location
kind: applicationType
properties: {
Application_Type: applicationType
}
}
resource diagnosticSetting 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: diagnosticSettingName
scope: appInsights
properties: {
storageAccountId: storageAccountId
logs: [
{
category: 'AppRequests'
enabled: true
}
]
metrics: [
{
category: 'AllMetrics'
enabled: true
}
]
}
}
若要使用診斷設定匯出遙測,請將下列程式代碼貼到您的範本中,並以您的特定值取代佔位元 <application-insights-resource-name>
、<azure-region-name>
、<application-type>
、<diagnostic-setting-name>
、 <subscription-id>
<resource-group>
和 <storage-account-name>
:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appInsightsName": {
"type": "string",
"defaultValue": "<application-insights-resource-name>"
},
"location": {
"type": "string",
"defaultValue": "<azure-region-name>"
},
"applicationType": {
"type": "string",
"defaultValue": "<application-type>"
},
"diagnosticSettingName": {
"type": "string",
"defaultValue": "<diagnostic-setting-name>"
},
"storageAccountId": {
"type": "string",
"defaultValue": "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>"
}
},
"resources": [
{
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02",
"name": "[parameters('appInsightsName')]",
"location": "[parameters('location')]",
"kind": "[parameters('applicationType')]",
"properties": {
"Application_Type": "[parameters('applicationType')]"
}
},
{
"type": "Microsoft.Insights/diagnosticSettings",
"apiVersion": "2021-05-01-preview",
"name": "[parameters('diagnosticSettingName')]",
"scope": "[resourceId('Microsoft.Insights/components', parameters('appInsightsName'))]",
"properties": {
"storageAccountId": "[parameters('storageAccountId')]",
"logs": [
{
"category": "AppRequests",
"enabled": true
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true
}
]
}
}
]
}
設定資料保留
您可以在相關聯的 Log Analytics 工作區中設定 Application Insights 資源的數據保留期。
如需詳細資訊,請參閱 設定分析數據表的預設互動式保留期間。
您可以在相關聯的 Log Analytics 工作區中設定 Application Insights 資源的數據保留期。
如需詳細資訊,請參閱 設定分析數據表的預設互動式保留期間。
您可以在相關聯的 Log Analytics 工作區中設定 Application Insights 資源的數據保留期。
如需詳細資訊,請參閱 設定分析數據表的預設互動式保留期間。
您可以在相關聯的 Log Analytics 工作區中設定 Application Insights 資源的數據保留期。
如需詳細資訊,請參閱 設定分析數據表的預設互動式保留期間。
若要設定相關聯 Log Analytics 工作區的資料保留期,請將下列程式碼貼到您的範本中,並以您的特定值取代佔位元 <log-analytics-workspace-name>
、<azure-region-name>
、<retention-period-in-days>
。
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
name: '<log-analytics-workspace-name>'
location: '<azure-region-name>'
properties: {
retentionInDays: <retention-period-in-days>
}
}
若要設定相關聯 Log Analytics 工作區的數據保留期,請將下列程式碼貼到您的範本中,並以您的特定值取代佔位符 <log-analytics-workspace-name>
、<azure-region-name>
、<retention-period-in-days>
。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-08-01",
"name": "<log-analytics-workspace-name>",
"location": "<azure-region-name>",
"properties": {
"retentionInDays": <retention-period-in-days>
}
}
]
}
設定每日上限
每日上限必須針對Application Insights和基礎Log Analytics工作區獨立設定。 有效的每日上限是兩個設定的最小值。
附註
目前,Azure 不會提供透過 Azure CLI 設定 Application Insights 每日上限的方法。
若要變更 Log Analytics 的每日上限,請在終端機中執行下列 Azure CLI 命令,並以您的特定值取代佔位元 <resource-group-name>
元、 <log-analytics-workspace-name>
和 <daily-cap-in-gb>
。
az monitor log-analytics workspace update --resource-group <resource-group-name> --workspace-name <log-analytics-workspace-name> --set workspaceCapping.dailyQuotaGb=<daily-cap-in-gb>
如需命令的詳細資訊 az monitor log-analytics workspace update
,請參閱 Azure CLI 檔。
若要變更 Application Insights 和 Log Analytics 的每日上限,請在終端機中執行下列 Azure PowerShell 命令,並以您的特定值取代佔位符。
Application Insights
預留位置:<resource-group-name>
、<application-insights-resource-name>
、<daily-cap-in-gb>
Set-AzApplicationInsightsDailyCap -ResourceGroupName <resource-group-name> -Name <application-insights-resource-name> -DailyCapGB <daily-cap-in-gb>
如需命令的詳細資訊 Set-AzApplicationInsightsDailyCap
,請參閱 Azure PowerShell 檔。
Log Analytics
預留位置:<resource-group-name>
、<log-analytics-workspace-name>
、<daily-cap-in-gb>
Set-AzOperationalInsightsWorkspace -ResourceGroupName <resource-group-name> -Name <log-analytics-workspace-name> -DailyQuotaGb <daily-cap-in-gb>
如需命令的詳細資訊 Set-AzOperationalInsightsWorkspace
,請參閱 Azure PowerShell 檔。
附註
目前,Azure 不提供使用 Azure CLI 設定 Application Insights 每日上限的方法。
若要變更 Log Analytics 的每日上限,請使用下列要求,並以您的特定值取代佔位元 <subscription-id>
、<resource-group-name>
、<log-analytics-workspace-name>
、、 <access-token>
<azure-region-name>
和 <daily-cap-in-gb>
:
預留位置:
PATCH https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>?api-version=2023-09-01
Authorization: Bearer <access-token>
Content-Type: application/json
{
"location": '<azure-region-name>',
"properties": {
"workspaceCapping": {
"dailyQuotaGb": <daily-cap-in-gb>,
},
}
}
如需設定 Log Analytics 每日上限的詳細資訊,請參閱 REST API 檔
附註
目前,Azure 不提供使用 Bicep 範本設定 Application Insights 每日上限的方法。
若要設定 Log Analytics 的每日上限,請將下列程式代碼貼到範本中,並以您的特定值取代佔位元 <log-analytics-workspace-name>
元、 <azure-region-name>
和 <daily-cap-in-gb>
:
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
name: '<log-analytics-workspace-name>'
location: '<azure-region-name>'
properties: {
dailyQuotaGb: <daily-cap-in-gb>
}
}
備註
目前,Azure 不提供使用 ARM 範本設定 Application Insights 每日上限的方法。
若要設定 Log Analytics 的每日上限,請將下列程式代碼貼到範本中,並以您的特定值取代佔位元 <log-analytics-workspace-name>
元、 <azure-region-name>
和 <daily-cap-in-gb>
:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2023-09-01",
"name": "<log-analytics-workspace-name>",
"location": "<azure-region-name>",
"properties": {
"workspaceCapping": {
"dailyQuotaGb": <daily-cap-in-gb>
}
}
}
]
}
設定定價方案
您可以在相關聯的 Log Analytics 工作區中設定 Application Insights 資源的定價方案。 如需可用定價方案的詳細資訊,請參閱 Azure 監視器記錄成本計算和選項。
附註
如果您在 Application Insights 中看到非預期的費用或高成本,本指南可協助您。 其中涵蓋常見的原因,例如高遙測量、資料擷取尖峰,以及取樣設定錯誤。 如果您要針對成本尖峰、遙測量、取樣無法運作、資料上限、高擷取量或非預期計費等相關問題進行疑難排解,此方式特別實用。 若要開始,請參閱 針對 Application Insights 中的高數據引入進行疑難排解。
若要設定定價方案,請在終端機中執行下列其中一個 Azure CLI 命令,並以您的特定值取代佔位元<log-analytics-workspace-name>
、 <azure-region-name>
和 (如果適用的話): <capacity-reservation-in-gb>
隨用隨付
az monitor log-analytics workspace update --resource-group <resource-group-name> --workspace-name <log-analytics-workspace-name> --set PerGB2018
承諾級別
az monitor log-analytics workspace update --resource-group <resource-group-name> --workspace-name <log-analytics-workspace-name> --set CapacityReservation --level <capacity-reservation-in-gb>
如需命令的詳細資訊 az monitor log-analytics workspace update
,請參閱 Azure CLI 檔。
若要設定定價方案,請在終端機中執行下列其中一個 Azure PowerShell 命令,並以您的特定值取代佔位元<log-analytics-workspace-name>
元、 <azure-region-name>
和 (如果適用的話): <capacity-reservation-in-gb>
隨用隨付
Set-AzOperationalInsightsWorkspace -ResourceGroupName <resource-group-name> -Name <log-analytics-workspace-name> -Sku perb2018
服務承諾等級
Set-AzOperationalInsightsWorkspace -ResourceGroupName <resource-group-name> -Name <log-analytics-workspace-name> -Sku capacityreservation -SkuCapacity <capacity-reservation-in-gb>
如需命令的詳細資訊 Set-AzOperationalInsightsWorkspace
,請參閱 Azure PowerShell 檔。
若要使用 REST API 設定定價方案,請使用下列其中一個要求,並以您的特定值取代佔位元 <subscription-id>
、<resource-group-name>
、<log-analytics-workspace-name>
、 <access-token>
和 (如果適用的話): <capacity-reservation-in-gb>
隨用隨付
PUT https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>/pricingPlans/current?api-version=2017-10-01
Content-Type: application/json
Authorization: Bearer <access-token>
{
"properties": {
"sku": {
"name": "pergb2018"
}
}
}
承諾級別
PUT https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.OperationalInsights/workspaces/<log-analytics-workspace-name>/pricingPlans/current?api-version=2017-10-01
Content-Type: application/json
Authorization: Bearer <access-token>
{
"properties": {
"sku": {
"name": "capacityreservation",
"capacityReservationLevel": <capacity-reservation-in-gb>
}
}
}
如需使用 REST API 設定定價方案的詳細資訊,請參閱 REST API 檔。
若要使用 Bicep 來設定定價方案,請將下列程式碼貼到您的範本中,並以您的特定值取代佔位符 <log-analytics-workspace-name>
、<azure-region-name>
,以及承諾等級中的 <capacity-reservation-in-gb>
。
隨用隨付
param workspaceName string = '<log-analytics-workspace-name>'
param workspaceRegion string = '<azure-region-name>'
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
name: workspaceName
location: workspaceRegion
properties: {
sku: {
name: 'pergb2018'
}
}
}
承諾等級
param workspaceName string = '<log-analytics-workspace-name>'
param workspaceRegion string = '<azure-region-name>'
param capacityReservationLevel int = '<capacity-reservation-in-gb>'
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
name: workspaceName
location: workspaceRegion
properties: {
sku: {
name: 'capacityreservation'
capacityReservationLevel: capacityReservationLevel
}
}
}
如需使用 Bicep 更新 Microsoft.OperationalInsights/workspaces
資源的詳細資訊,請參閱 範本檔。
若要使用 ARM 範本設定定價方案,請將下列程式代碼貼到您的範本中,並以您的特定值取代佔位符 <log-analytics-workspace-name>
、<azure-region-name>
,以及在承諾層中的 <capacity-reservation-in-gb>
。
隨用隨付
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string",
"defaultValue": "<log-analytics-workspace-name>"
},
"workspaceRegion": {
"type": "string",
"defaultValue": "<azure-region-name>"
}
},
"resources": [
{
"name": "[parameters('workspaceName')]",
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-08-01",
"location": "[parameters('workspaceRegion')]",
"properties": {
"sku": {
"name": "pergb2018"
}
}
}
]
}
承諾層級
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string",
"defaultValue": "<log-analytics-workspace-name>"
},
"workspaceRegion": {
"type": "string",
"defaultValue": "<azure-region-name>"
},
"capacityReservationLevel": {
"type": "int",
"defaultValue": <capacity-reservation-in-gb>
}
},
"resources": [
{
"name": "[parameters('workspaceName')]",
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-08-01",
"location": "[parameters('workspaceRegion')]",
"properties": {
"sku": {
"name": "capacityreservation",
"capacityReservationLevel": "[parameters('capacityReservationLevel')]"
}
}
}
]
}
如需使用ARM範本更新 Microsoft.OperationalInsights/workspaces
資源的詳細資訊,請參閱 範本檔。
停用IP遮罩
根據預設,Application Insights 不會儲存IP位址。 若要瞭解如何停用IP遮罩,請參閱 地理位置和IP位址處理。
建立其他資源
建立可用性測試
若要使用預設設定建立標準可用性測試,請在終端機中執行下列 Azure CLI 命令,並以您的特定值取代佔位元 <resource-group-name>
、 <azure-region-name>
、 <web-test-name>
、 <url>
、 <subscription-id>
和 <application-insights-resource-name>
:
az monitor app-insights web-test create --resource-group <resource-group-name> \
--location <azure-region-name> \
--web-test-kind standard \
--name <web-test-name> \
--defined-web-test-name <web-test-name> \
--request-url <url> \
--retry-enabled true \
--ssl-check true \
--ssl-lifetime-check 7 \
--frequency 300 \
--locations Id="us-ca-sjc-azr" \
--locations Id="apac-sg-sin-azr" \
--locations Id="us-il-ch1-azr" \
--locations Id="us-va-ash-azr" \
--locations Id="emea-au-syd-edge" \
--http-verb GET \
--timeout 120 \
--expected-status-code 200 \
--enabled true \
--tags hidden-link:/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>=Resource
如需命令的詳細資訊 az monitor app-insights web-test create
,請參閱 Azure CLI 檔。
附註
Web 測試區域 (-location
) 與地理位置(-locations
請注意複數形式)不同,可以選取多個。 -location
是指建立和裝載 Web 測試的 Azure 區域,同時-locations
參考執行 Web 測試的地理位置或位置。 如需所有地理位置的完整清單,請參閱 Application Insights 可用性測試。
若要使用預設設定建立標準可用性測試,請在終端機中執行下列 Azure PowerShell 命令,並以您的特定值取代佔位元 <resource-group-name>
元 、 <azure-region-name>
、 <web-test-name>
、 <url>
、 <subscription-id>
和 <application-insights-resource-name>
:
$geoLocation = @()
$geoLocation += New-AzApplicationInsightsWebTestGeolocationObject -Location "us-ca-sjc-azr"
$geoLocation += New-AzApplicationInsightsWebTestGeolocationObject -Location "apac-sg-sin-azr"
$geoLocation += New-AzApplicationInsightsWebTestGeolocationObject -Location "us-il-ch1-azr"
$geoLocation += New-AzApplicationInsightsWebTestGeolocationObject -Location "us-va-ash-azr"
$geoLocation += New-AzApplicationInsightsWebTestGeolocationObject -Location "emea-au-syd-edge"
New-AzApplicationInsightsWebTest -ResourceGroupName <resource-group-name> `
-Location <azure-region-name> `
-Name <web-test-name> `
-TestName <web-test-name> `
-Kind standard `
-RequestUrl <url> `
-RetryEnabled `
-RuleSslCheck `
-RuleSslCertRemainingLifetimeCheck 7 `
-Frequency 300 `
-GeoLocation $geoLocation `
-RequestHttpVerb GET `
-Timeout 120 `
-RuleExpectedHttpStatusCode 200 `
-Enabled `
-Tag @{"hidden-link:/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>" = "Resource"}
如需命令的詳細資訊 New-AzApplicationInsightsWebTest
,請參閱 Azure PowerShell 檔。
備註
Web 測試區域 (-Location
) 與可以選取多個的地理位置 (-GeoLocation
) 不同。 -Location
是指建立和裝載 Web 測試的 Azure 區域,同時 -GeoLocation
參考執行 Web 測試的地理位置或位置。 如需所有地理位置的完整清單,請參閱 Application Insights 可用性測試。
若要使用 REST API 建立具有預設設定的標準可用性測試,請使用下列要求,並以您的特定值取代佔位元 <subscription-id>
、<resource-group-name>
、<application-insights-resource-name>
、、<web-test-name>
<access-token>
、 <azure-region-name>
和 <url>
:
PUT https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>/webtests/<web-test-name>?api-version=2021-08-01
Content-Type: application/json
Authorization: Bearer <access-token>
{
"location": "<azure-region-name>",
"properties": {
"Name": "<web-test-name>",
"SyntheticMonitorId": "<web-test-name>",
"Enabled": true,
"Frequency": 300,
"Timeout": 120,
"Kind": "standard",
"RetryEnabled": true,
"Request": {
"RequestUrl": "<url>",
"HttpVerb": "GET"
},
"ValidationRules": {
"ExpectedHttpStatusCode": 200,
"SslCheck": true,
"SslCertRemainingLifetimeCheck": 7
},
"Locations": [
{
"Id": "us-ca-sjc-azr"
},
{
"Id": "apac-sg-sin-azr"
},
{
"Id": "us-il-ch1-azr"
},
{
"Id": "us-va-ash-azr"
},
{
"Id": "emea-au-syd-edge"
}
]
},
"Tags": {
"hidden-link:/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>": "Resource"
}
}
備註
Web 測試區域 (-location
) 與地理位置(-Locations
請注意複數形式)不同,可以選取多個。 -location
是指建立和裝載 Web 測試的 Azure 區域,同時 -Locations
參考執行 Web 測試的地理位置或位置。 如需所有地理位置的完整清單,請參閱 Application Insights 可用性測試。
若要深入瞭解如何使用 REST API 建立和設定 Web 測試,請參閱我們的 REST API 檔。
若要使用 Bicep 建立具有預設設定的標準可用性測試,請將下列程式代碼新增至範本,並以您的特定值取代佔位元<web-test-name>
、<azure-region-name>
、<subscription-id>
、、 <resource-group-name>
<application-insights-resource-name>
和 <url>
:
resource webTest 'microsoft.insights/webtests@2022-06-15' = {
name: '<web-test-name>'
location: '<azure-region-name>'
tags: {
'hidden-link:/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>': 'Resource'
}
properties: {
SyntheticMonitorId: '<web-test-name>'
Name: '<web-test-name>'
Enabled: true
Frequency: 300
Timeout: 120
Kind: 'standard'
RetryEnabled: true
Locations: [
{
Id: 'us-ca-sjc-azr'
}
{
Id: 'apac-sg-sin-azr'
}
{
Id: 'us-il-ch1-azr'
}
{
Id: 'us-va-ash-azr'
}
{
Id: 'emea-au-syd-edge'
}
]
Request: {
RequestUrl: '<url>'
HttpVerb: 'GET'
}
ValidationRules: {
ExpectedHttpStatusCode: 200
SSLCheck: true
SSLCertRemainingLifetimeCheck: 7
}
}
}
備註
Web 測試區域 (location
) 與可以選取多個的地理位置 (Locations
) 不同。 location
是指建立和裝載 Web 測試的 Azure 區域,同時 Locations
參考執行 Web 測試的地理位置或位置。 如需所有地理位置的完整清單,請參閱 Application Insights 可用性測試。
如需使用 Bicep 建立可用性測試的詳細資訊,請參閱 Microsoft.Insights Webtests。
若要使用 ARM 範本建立具有預設設定的標準可用性測試,請將下列程式代碼新增至範本,並以您的特定值取代佔位元 <web-test-name>
、<azure-region-name>
、<resource-group-name>
<application-insights-resource-name>
<subscription-id>
和 :<url>
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "microsoft.insights/webtests",
"apiVersion": "2022-06-15",
"name": "<web-test-name>",
"location": "<azure-region-name>",
"tags": {
"hidden-link:/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>": "Resource"
},
"properties": {
"SyntheticMonitorId": "<web-test-name>",
"Name": "<web-test-name>",
"Enabled": true,
"Frequency": 300,
"Timeout": 120,
"Kind": "standard",
"RetryEnabled": true,
"Locations": [
{
"Id": "us-ca-sjc-azr"
},
{
"Id": "apac-sg-sin-azr"
},
{
"Id": "us-il-ch1-azr"
},
{
"Id": "us-va-ash-azr"
},
{
"Id": "emea-au-syd-edge"
}
],
"Request": {
"RequestUrl": "<url>",
"HttpVerb": "GET"
},
"ValidationRules": {
"ExpectedHttpStatusCode": 200,
"SSLCheck": true,
"SSLCertRemainingLifetimeCheck": 7
}
}
}
]
}
附註
Web 測試區域 (location
) 與可以選取多個的地理位置 (Locations
) 不同。 location
是指建立和裝載 Web 測試的 Azure 區域,同時 Locations
參考執行 Web 測試的地理位置或位置。 如需所有地理位置的完整清單,請參閱 Application Insights 可用性測試。
如需使用ARM範本建立可用性測試的詳細資訊,請參閱 Microsoft.Insights webtests。
新增度量警示
小提示
每個 Application Insights 資源都隨附現成可用的計量。 如果個別元件會回報給相同的 Application Insights 資源,則針對這些計量發出警示可能沒有意義。
若要自動建立計量警示,請參閱計量警示範本文章。
建立更多 Application Insights 資源
我應該部署多少 Application Insights 資源?
當您在開發下一版 Web 應用程式時,您不會想看到新版與已發行版本的 Application Insights 遙測混合在一起。
為了避免混淆,請將不同開發階段的遙測,以個別的連接字串傳送到個別的 Application Insights 資源。
如果您的系統是 Azure 雲端服務的執行個體,則會有另一種設定個別連接字串的方法。
使用單一 Application Insights 資源的時機
使用單一 Application Insights 資源以:
- 簡化部署在一起之應用程式的 DevOps/ITOps 管理,通常是由同一個小組開發及管理。
- 預設會在儀表板中集中處理關鍵效能指標,例如回應時間和失敗率。 視需要在計量總管中依角色名稱區隔。
- 當應用程式元件之間不需要不同的 Azure 角色型存取控制管理時。
- 當相同的計量警示準則、連續匯出和跨元件計費/配額管理都足夠時。
- 當 API 金鑰可以平等存取所有元件的資料,且 10 個 API 金鑰符合所有元件的需求時。
- 當相同的智慧偵測和工作項目整合設定適用於所有角色時。
附註
如果您要合併多個 Application Insights 資源,您可以將現有應用程式元件指向新的合併 Application Insights 資源。 儲存在您舊資源的遙測不會傳輸到新的資源。 只有在新資源中有足夠的遙測資料以確保業務持續性時,才刪除舊資源。
其他考量
若要啟用入口網站體驗,請新增自訂程式碼,將有意義的值指派給 Cloud_RoleName 屬性。 如果沒有這些值,入口網站功能就無法運作。
對於 Azure Service Fabric 應用程式和經典雲端服務,SDK 會透過讀取 Azure 角色環境來自動設定服務。 針對其他應用程式類型,您通常需要明確設定它。
即時計量無法依角色名稱分割資料。
版本和版次追蹤
當您發佈新版本的應用程式時,您想要能夠將遙測與不同的組建分開。 您可以設定 [應用程式版本] 屬性,以便篩選 搜尋 和 計量總管 結果。
設定 [應用程式版本] 屬性有幾種不同的方法。
選項 1: 直接設定版本
將這一行 telemetryClient.Context.Component.Version = typeof(MyProject.MyClass).Assembly.GetName().Version;
新增至應用程式的初始化程序代碼。
為了確保所有 TelemetryClient
實例都一致地設定,請將該行包裝在 遙測初始化器中。
選項 2: 在 中 BuildInfo.config
設定版本(僅限 ASP.NET)
Application Insights Web 模組會從 BuildLabel
節點挑選版本。 在您的專案中包含此檔案,而且記得要在方案總管中設定 [永遠複製] 屬性。
<?xml version="1.0" encoding="utf-8"?>
<DeploymentEvent xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/DeploymentEvent/2013/06">
<ProjectName>AppVersionExpt</ProjectName>
<Build type="MSBuild">
<MSBuild>
<BuildLabel kind="label">1.0.0.2</BuildLabel>
</MSBuild>
</Build>
</DeploymentEvent>
在Microsoft組建引擎中自動產生 BuildInfo.config
。 將下列幾行新增至您的 .csproj
檔案:
<PropertyGroup>
<GenerateBuildInfoConfigFile>true</GenerateBuildInfoConfigFile>
<IncludeServerNameInBuildInfo>true</IncludeServerNameInBuildInfo>
</PropertyGroup>
此步驟會產生一個名為 yourProjectName.BuildInfo.config
的檔案。 發佈程序會將這個檔案重新命名為 BuildInfo.config
。
當您使用 Visual Studio 組建時,組建標籤會包含預留位置 (*AutoGen_...*)
。 使用 Microsoft 組建引擎建置時,佔位元元會填入正確的版本號碼。
若要允許 Microsoft Build Engine 產生版本號碼,請在 1.0.*
中設定類似 AssemblyReference.cs
的版本。
版本註釋
如果您使用 Azure DevOps,您可以取得註解標記 (每當發行新版本時,此標記就會新增至您的圖表)。
自動化資源建立過程
您可以使用 Bicep 或 JSON 範本搭配 Azure Resource Manager 來自動化資源建立程式。 您可以將數個資源封裝在一起,以在一個部署中加以建立。 例如,您可以使用可用性測試、計量警示和診斷設定來建立 Application Insights 資源,以將遙測傳送至 Azure 記憶體帳戶。
在 Azure 入口網站中產生範本
您可以從現有的資源產生範本。
僅限 Application Insights
- 移至 Azure 入口網站中的 Application Insights 資源。
- 在左側導覽列的 [自動化] 底下開啟 [導出] 範本。
- (選擇性):若要使用您自己的參數,請取消核取 [包含參數]。
- 下載 範本檔案,或直接在 Azure 入口網站中 加以部署 。
多個資源
- 移至 Application Insights 資源的資源群組。
- 在 [ 概觀] 窗格中,標示您想要包含在範本中的所有資源,然後選取頂端導覽列中的 [導出範本 ]。
- (選擇性):若要使用您自己的參數,請取消核取 [包含參數]。
- 下載 範本檔案,或直接在 Azure 入口網站中 加以部署 。
從頭開始建立範本
若要瞭解如何從頭開始建立 ARM 範本,請流覽 ARM 範本檔 ,其中包含 建立範本、 新增資源、 新增參數等教學課程。
您可以在 Azure 資源參考檔中找到 Application Insights、可用性測試、計量警示、診斷設定和其他資源的可用屬性,請參閱參考>監視器>深入解析節點底下的 Azure 資源參考檔。
常見問題集
本節提供常見問題的答案。
如何將 Application Insights 資源移至新區域?
不支援在區域之間傳輸現有的 Application Insights 資源,而且您無法將歷程記錄資料遷移至新區域。 因應措施包括:
- 在所需的區域中建立新的 Application Insights 資源。
- 在新的資源中重新創建原始資源中的任何獨特自訂設置。
- 使用新區域資源的連接字串更新您的應用程式。
- 測試以確保所有專案都如預期般運作,並搭配新的 Application Insights 資源使用。
- 決定要保留還是刪除原始的 Application Insights 資源。 刪除傳統資源表示遺失所有歷程記錄數據。 如果資源是工作區型資源,則資料會保留在 Log Analytics 中,以便在保留期間到期之前存取歷程記錄資料。
在新區域中,通常需要手動重新建立或更新資源的獨特自訂化項目,包括但不限於:
- 重新建立自訂儀表板和活頁簿。
- 重新建立或更新任何自訂記錄/計量警示的範圍。
- 重新建立可用性警示。
- 重新建立您的使用者存取新資源所需的自訂 Azure 角色型存取控制。
- 複寫牽涉到內嵌取樣、資料保留、每日上限和自訂計量的設定。 這些設定會透過使用者和預估成本窗格控制。
- 需要 API 金鑰的任何整合,例如版本註釋和即時計量安全控制通道。 您必須產生新的 API 金鑰,並更新相關聯的整合。
- 必須重新設定舊版資源中的持續匯出功能。
- 以工作區為基礎的資源中的診斷設定必須重新設定。
我可以在 Azure Resource Manager 部署中使用 `providers('Microsoft.Insights', 'components').apiVersions[0]` 嗎?
我們不建議使用此方法來填入 API 版本。 最新版本可代表其中可能包含中斷性變更的預覽版本。 即使使用較新的非預覽版本,API 版本也不一定與現有範本回溯相容。 在某些情況下,API 版本可能無法供所有訂用帳戶使用。
下一步