संपादित करें

इसके माध्यम से साझा किया गया


Autoscale a web app by using custom metrics

This article takes you through how to set up autoscale for a web app by using a custom metric in the Azure portal.

Autoscale allows you to add and remove resources to handle increases and decreases in load. In this article, we'll show you how to set up autoscale for a web app by using one of the Application Insights metrics to scale the web app in and out.

Note

Autoscaling on custom metrics in Application Insights is supported only for metrics published to Standard and Azure.ApplicationInsights namespaces. If any other namespaces are used for custom metrics in Application Insights, it returns an Unsupported Metric error.

Azure Monitor autoscale applies to:

Prerequisite

You must have an Azure account with an active subscription. You can create an account for free.

Overview

To create an autoscaled web app:

  1. If you don't already have one, create an App Service plan. You can't set up autoscale for free or basic tiers.
  2. If you don't already have one, create a web app by using your service plan.
  3. Configure autoscaling for your service plan.

Create an App Service plan

An App Service plan defines a set of compute resources for a web app to run on.

  1. Open the Azure portal.

  2. Search for and select App Service plans.

    Screenshot that shows searching for App Service plans.

  3. On the App Service plan page, select Create.

  4. Select a Resource group or create a new one.

  5. Enter a Name for your plan.

  6. Select an Operating system and Region.

  7. Select an SKU and size.

    Note

    You can't use autoscale with free or basic tiers.

  8. Select Review + create > Create.

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

Create a web app

  1. Search for and select App services.

    Screenshot that shows searching for App Services.

  2. On the App Services page, select Create.

  3. On the Basics tab, enter a Name and select a Runtime stack.

  4. Select the Operating System and Region that you chose when you defined your App Service plan.

  5. Select the App Service plan that you created earlier.

  6. Select the Monitoring tab.

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

  7. On the Monitoring tab, select Yes to enable Application Insights.

  8. Select Review + create > Create.

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

Configure autoscale

Configure the autoscale settings for your App Service plan.

  1. Search and select autoscale in the search bar or select Autoscale under Monitor in the menu bar on the left.

  2. Select your App Service plan. You can only configure production plans.

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

Set up a scale-out rule

Set up a scale-out rule so that Azure spins up another instance of the web app when your web app is handling more than 70 sessions per instance.

  1. Select Custom autoscale.

  2. In the Rules section of the default scale condition, select Add a rule.

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

  3. From the Metric source dropdown, select Other resource.

  4. From Resource type, select Application Insights.

  5. From the Resource dropdown, select your web app.

  6. Select a Metric name to base your scaling on. For example, use Sessions.

  7. Select the Enable metric divide by instance count checkbox so that the number of sessions per instance is measured.

  8. From the Operator dropdown, select Greater than.

  9. Enter the Metric threshold to trigger the scale action. For example, use 70.

  10. Under Action, set Operation to Increase count by. Set Instance count to 1.

  11. Select Add.

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

Set up a scale-in rule

Set up a scale-in rule so that Azure spins down one of the instances when the number of sessions your web app is handling is less than 60 per instance. Azure reduces the number of instances each time this rule is run until the minimum number of instances is reached.

  1. In the Rules section of the default scale condition, select Add a rule.

  2. From the Metric source dropdown, select Other resource.

  3. From Resource type, select Application Insights.

  4. From the Resource dropdown, select your web app.

  5. Select a Metric name to base your scaling on. For example, use Sessions.

  6. Select the Enable metric divide by instance count checkbox so that the number of sessions per instance is measured.

  7. From the Operator dropdown, select Less than.

  8. Enter the Metric threshold to trigger the scale action. For example, use 60.

  9. Under Action, set Operation to Decrease count by and set Instance count to 1.

  10. Select Add.

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

Limit the number of instances

  1. Set the maximum number of instances that can be spun up in the Maximum field of the Instance limits section. For example, use 4.

  2. Select Save.

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

Clean up resources

If you're not going to continue to use this application, delete resources.

  1. On the App Service overview page, select Delete.

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

  2. On the Autoscale setting page, in the JSON tab, select the trash bin icon next to the Autoscale setting name. Note that the autoscale settings aren't deleted along with the App Service plan unless you delete the resource group. If you don't delete the Autoscale settings and you recreate an app service plan with the same name, it inherits the original autoscale settings.

  3. On the App Service plans page, select Delete.

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

Next steps

To learn more about autoscale, see the following articles: