共用方式為


使用自訂計量自動調整 Web 應用程式

本文說明如何在 Azure 入口網站中使用自訂計量來設定 Web 應用程式的自動調整。

自動調整可讓您新增和移除資源以因應負載的增加和減少。 在本文中,我們將示範如何使用其中一個 Application Insights 計量來來設定 Web 應用程式的自動調整,藉此相應縮減和擴大 Web 應用程式。

注意

只有發佈至 StandardAzure.ApplicationInsights 命名空間的計量,才支援在 Application Insights 中對自訂計量進行自動調整。 如果您針對 Application Insights 中的自訂計量使用任何其他命名空間,則將傳回不支援的計量錯誤。

Azure 監視器的自動調整適用於:

必要條件

您需要具有有效訂用帳戶的 Azure 帳戶。 您可以免費建立帳戶

概觀

若要建立自動調整的 Web 應用程式:

  1. 如果您尚未擁有方案,請建立 App Service 方案。 您無法針對免費或基本層設定自動調整。
  2. 如果您還沒有 Web 應用程式,請使用您的服務方案來建立 Web 應用程式
  3. 針對服務方案設定自動調整

建立 App Service 方案

App Service 方案定義一組計算資源供 Web 應用程式執行。

  1. 開啟 Azure 入口網站

  2. 搜尋並選取 [App Service 方案]

    Screenshot that shows searching for App Service plans.

  3. 在 [App Service 方案] 頁面上,選取 [建立]

  4. 選取 [資源群組] 或建立新的資源群組。

  5. 輸入方案的 [名稱]

  6. 選取 [作業系統] 和 [區域]

  7. 選取 [SKU] 和 [大小]

    注意

    您無法在免費或基本層使用自動調整。

  8. 選取 [檢閱 + 建立]>[建立]

    Screenshot that shows the Basics tab of the Create App Service Plan screen on which you configure the App Service plan.

建立 Web 應用程式

  1. 搜尋並選取 [應用程式服務]

    Screenshot that shows searching for App Services.

  2. 在 [應用程式服務] 頁面上,選取 [建立]

  3. 在 [基本] 索引標籤上,輸入 [名稱],然後選取 [執行階段堆疊]

  4. 選取您在定義 App Service 方案時所選擇的作業系統區域

  5. 選取您稍早建立的 App Service 方案

  6. 選取 [監控] 索引標籤。

    Screenshot that shows the Basics tab of the Create Web App page where you set up a web app.

  7. 在 [監視] 索引標籤上,選取 [是] 以啟用 Application Insights。

  8. 選取 [檢閱 + 建立]>[建立]

    Screenshot that shows the Monitoring tab of the Create Web App page where you enable Application Insights.

設定自動調整

設定 App Service 方案的自動調整設定。

  1. 在搜尋列中搜尋並選取自動調整,或在左側功能表列的 [監視] 底下選取 [自動調整]

  2. 選取您的 App Service 方案。 您只能設定實際執行方案。

    Screenshot that shows the Autoscale page where you select the resource to set up autoscale.

設定擴大規則

設定擴大規則,讓 Azure 在 Web 應用程式針對每個執行個體處理超過 70 個工作階段時,啟動另一個 Web 應用程式的執行個體。

  1. 選取 [自訂自動調整]

  2. 在預設縮放條件的 [規則] 區段中,選取 [新增規則]

    Screenshot that shows the Autoscale setting page where you set up the basic autoscale settings.

  3. 從 [計量來源] 下拉式清單中,選取 [其他資源]

  4. 從 [資源類型] 中,選取 [Application Insights]

  5. 從 [資源] 下拉式清單中,選取您的 Web 應用程式。

  6. 選取調整所依據的 [計量名稱]。 例如,使用 [工作階段]

  7. 選取 [啟用計量除以執行個體計數] 核取方塊,藉此測量每個執行個體的工作階段數目。

  8. 從 [運算子] 下拉式清單中,選取 [大於]

  9. 輸入用於觸發調整動作的計量閾值。 例如,使用 70

  10. 在 [動作] 底下,將 [作業] 設定為 [將計數增加]。 將 [執行個體計數] 設為 1

  11. 選取 [新增]。

    Screenshot that shows the Scale rule page where you configure the scale-out rule.

設定縮減規則

設定縮減規則,讓 Azure 在 Web 應用程式針對每個執行個體處理的工作階段數目小於 60 個時,所檢其中一個執行個體。 Azure 會在每次執行此規則時減少執行個體數目,直到達到執行個體數目下限為止。

  1. 在預設縮放條件的 [規則] 區段中,選取 [新增規則]

  2. 從 [計量來源] 下拉式清單中,選取 [其他資源]

  3. 從 [資源類型] 中,選取 [Application Insights]

  4. 從 [資源] 下拉式清單中,選取您的 Web 應用程式。

  5. 選取調整所依據的 [計量名稱]。 例如,使用 [工作階段]

  6. 選取 [啟用計量除以執行個體計數] 核取方塊,藉此測量每個執行個體的工作階段數目。

  7. 從 [運算子] 下拉式清單中,選取 [小於]

  8. 輸入用於觸發調整動作的計量閾值。 例如,使用 60

  9. 在 [動作] 底下,將 [運算] 設定為 [減少計數],並將 [執行個體計數] 設定為 1

  10. 選取 [新增]。

    Screenshot that shows the Scale rule page where you configure the scale-in rule.

限制執行個體數目

  1. 在 [執行個體限制] 區段的 [最大值] 欄位中設定可啟動的執行個體數目上限。 例如,使用 4

  2. 選取 [儲存]。

    Screenshot that shows the Autoscale setting page where you set up instance limits.

清除資源

如果您不打算繼續使用此應用程式,請刪除資源。

  1. 在 App Service 概觀頁面上,按一下 [刪除]

    Screenshot that shows the App Service page where you can delete the web app.

  2. 在 [自動調整設定] 頁面上,於 [JSON] 索引標籤中,選取 [自動調整設定名稱] 旁的垃圾桶圖示。 請注意,除非您刪除資源群組,否則自動調整設定不會與 App Service 方案一起刪除。 如果您未刪除自動調整設定,而且重新建立具有相同名稱的 App Service 方案,則會繼承原始的自動調整設定。

  3. 在 [App Service 方案] 頁面上,選取 [刪除]

    Screenshot that shows the App Service plans page where you can delete the App Service plan.

下一步

若要深入了解自動調整規模,請參閱下列文章: