在 Azure 中根据自定义指标自动缩放入门Get started with auto scale by custom metric in Azure

本文介绍如何在 Azure 门户中根据自定义指标缩放资源。This article describes how to scale your resource by a custom metric in Azure portal.

Azure Monitor 自动缩放仅适用于虚拟机规模集云服务应用服务 - Web 应用Azure 数据资源管理器群集Azure Monitor autoscale applies only to Virtual Machine Scale Sets, Cloud Services, App Service - Web Apps, Azure Data Explorer Cluster ,
集成服务环境和 API 管理服务Integration Service Environment and API Management services.

入门Lets get started

本文假定已有一个配了 Application Insights 的 Web 应用。This article assumes that you have a web app with application insights configured. 如果还没有,则可以为 ASP.NET 网站设置 Application InsightsIf you don't have one already, you can set up Application Insights for your ASP.NET website

  • 打开 Azure 门户Open Azure portal
  • 单击左侧导航窗格中的 Azure Monitor 图标。Click on Azure Monitor icon in the left navigation pane. 启动 Azure MonitorLaunch Azure Monitor
  • 单击“自动缩放设置”可查看适用自动缩放的所有资源及其当前自动缩放状态在 Azure Monitor 中发现自动缩放Click on Autoscale setting to view all the resources for which auto scale is applicable, along with its current autoscale status Discover auto scale in Azure monitor
  • 在 Azure Monitor 中打开“自动缩放”边栏选项卡,并选择要缩放的资源Open 'Autoscale' blade in Azure Monitor and select a resource you want to scale

    注意:以下步骤使用的应用服务计划与某个已配置 app insights 的 Web 应用相关联。Note: The steps below use an app service plan associated with a web app that has app insights configured.

  • 在资源的“缩放设置”边栏选项卡中,请注意当前实例计数为 1。In the scale setting blade for the resource, notice that the current instance count is 1. 单击“启用自动缩放”。Click on 'Enable autoscale'. 新 Web 应用的缩放设置Scale setting for new web app
  • 提供缩放设置的名称,并单击“添加规则”。Provide a name for the scale setting, and the click on "Add a rule". 请注意右侧以上下文窗格形式打开的缩放规则选项。Notice the scale rule options that opens as a context pane in the right hand side. 默认情况下,它将选项设置为:如果资源的 CPU 百分比超过 70%,将实例计数缩放 1。By default, it sets the option to scale your instance count by 1 if the CPU percentage of the resource exceeds 70%. 将顶部的指标源更改为“Application Insights”,在“资源”下拉列表中选择 app insights 资源,并选择要基于其缩放的自定义指标。Change the metric source at the top to "Application Insights", select the app insights resource in the 'Resource' dropdown and then select the custom metric based on which you want to scale. 根据自定义指标缩放Scale by custom metric
  • 与上面的步骤类似,添加这样一个缩放规则:如果自定义指标低于阈值,将横向缩减并将规模计数减 1。Similar to the step above, add a scale rule that will scale in and decrease the scale count by 1 if the custom metric is below a threshold. 基于 CPU 进行缩放Scale based on cpu
  • 设置实例限制。Set the instance limits. 例如,如果要根据自定义指标波动在 2-5 个实例之间进行缩放,请将“最小值”设置为“2”,将“最大值”设置为“5”,并将“默认值”设置为“2”For example, if you want to scale between 2-5 instances depending on the custom metric fluctuations, set 'minimum' to '2', 'maximum' to '5' and 'default' to '2'

    注意:如果读取资源指标时出现问题,且当前容量低于默认容量,则要确保资源的可用性,自动缩放将扩大到默认值。Note: In case there is a problem reading the resource metrics and the current capacity is below the default capacity, then to ensure the availability of the resource, Autoscale will scale out to the default value. 如果当前容量已大于默认容量,则自动缩放不会横向缩减。If the current capacity is already higher than default capacity, Autoscale will not scale in.

  • 单击“保存”Click on 'Save'

祝贺。Congratulations. 现在已成功创建缩放设置,以基于自定义指标自动缩放 Web 应用。You now successfully created your scale setting to auto scale your web app based on a custom metric.

注意:若要开始使用 VMSS 或云服务角色,也可以运用相同的步骤。Note: The same steps are applicable to get started with a VMSS or cloud service role.