Auto scale on azure app service command throwing ["UnsupportedMetric"] error

1.9k views Asked by At

Following az-cli command not supporting metric for auto-scaling instances on azure app services.

# Create cpu autoscale rule
az monitor autoscale rule create --resource-group $COMMON_RESOURCE_GROUP_NAME   \
  --subscription $SUBSCRIPTION_ID   \
  --resource $WEBAPP_NAME   \
  --resource-type 'Microsoft.Web/sites'   \
  --autoscale-name "test"  \
  --condition "Percentage CPU > 75 avg 5m"  \
  --scale out 1 

Response - Exception of type 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was thrown.. [Code: "UnsupportedMetric"]

I followed this Microsoft documentation - https://learn.microsoft.com/en-us/cli/azure/monitor/autoscale/rule?view=azure-cli-latest

I know, how to do auto-scale through azure portal but I want to do this using script.

3

There are 3 answers

2
Joey Cai On

Basically you create a rule based on how many request the web app gets and scales out its related service plan.

az monitor autoscale rule create  --resource-group MyResourceGroup   `
--resource MyWebSite  `
--resource-type 'Microsoft.Web/sites' `
--autoscale-name MyAutoScale    `
--condition "Requests >= 200 avg 5m"   `
--scale out 2
0
abhit pahwa On

I also tried with "Percentage CPU > 75 avg 5m" and got the same result "Unsupported Metric". I tried creating the rule manually and looked at the JSON properties, the metric was mentioned as CpuPercentage. So, with the following change in condition, it worked.

az monitor autoscale rule create \
--resource-group $resource \
--autoscale-name $autoscalename \
--scale out 1 \
--condition "CpuPercentage > 70 avg 5m"
0
kramfs On

I was able to create an autoscaling policy and rules with the following steps.

NOTE: This is specific to Azure Service Plan but might work with other vmss.

The Azure docs is specifically geared towards VMSS - https://learn.microsoft.com/en-us/cli/azure/monitor/autoscale?view=azure-cli-latest so I had to manually create a Autoscale and rule, and view the JSON output to see the actual metrics name used.

RG="resource_group"
RESOURCE="service_plan_name"

First, create the Autoscale

az monitor autoscale create -g $RG --resource $RESOURCE \
--min-count 1 --max-count 4 --count 1 --email-administrator \
--resource-type Microsoft.Web/serverfarms

And then, create the scale Up/Down rule

az monitor autoscale rule create -g $RG --autoscale-name $RESOURCE \
--scale out 1 --condition "CpuPercentage > 80 avg 5m"

az monitor autoscale rule create -g $RG --autoscale-name $RESOURCE \
--scale in 1 --condition "CpuPercentage <= 40 avg 10m"