0
votes

I'm looking to use Azure Powershell to disable auto-scaling on an AZVMSS I've created during deploy to avoid hangups in the deploy process with our deploy server(the problem is our software tries to do too much at once and it makes a 5 minute deploy take an hour, but that's a problem for a different time).

Through some experimentation I've come to learn that the custom metric that we are writing to app insights is not considered "valid" via powershell but is valid in the portal, as in I can select it and make a rule manually.

When I look in the JSON for my autoscale settings I see the name of the metric and copy-paste it into my script. It matches the visible option in the dropdown from the app insights account that I have created and can see in the portal. However when I run my commands powershell tells me that parameters are invalid.

Am I just not allowed to use custom metrics? How do I specify them if so? I also noticed that "Last" as TimeAggregationOperator type is not allowed in script even though the docs say it is usable (then don't show it) and it's usable in the portal. Am I correct in thinking that this is a lost cause?

$scaleoutRule = New-AzAutoscaleRule -MetricName "$myCustomMetricName" `
    -MetricResourceId "/subscriptions/$sub/resourceGroups/$rg/providers/microsoft.insights/components/$appInsightsAccountName" `
    -Operator GreaterThan `
    -MetricStatistic Average `
    -Threshold 30 `
    -TimeAggregationOperator Count `
    -TimeGrain 00:01:00 `
    -TimeWindow 00:10:00 `
    -ScaleActionCooldown 00:10:00 `
    -ScaleActionDirection Increase `
    -ScaleActionScaleType ChangeCount `
    -ScaleActionValue "1"

$Profile1 = New-AzAutoscaleProfile -DefaultCapacity "2" `
    -MaximumCapacity "10" `
    -MinimumCapacity "2" `
    -Rule $Rule1 -Name "default"


Add-AzAutoscaleSetting -Location 'eastus2' `
    -Name "mySetting" `
    -ResourceGroupName "$rg" `
    -TargetResourceId "/subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.Compute/virtualMachineScaleSets/$azvmss" `
    -AutoscaleProfile $Profile1

This is often met with

Add-AzAutoscaleSetting : Exception type: ErrorResponseException, Message: Exception of type 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was thrown., Code: UnsupportedMetric, 
Status code:BadRequest, Reason phrase: Bad Request    
 + CategoryInfo          : CloseError: (:) [Add-AzAutoscaleSetting], PSInvalidOperationException

+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Autoscale.AddAzureRmAutoscaleSettingCommand
1

1 Answers

0
votes

For VMSS in Azure you have 3 options for Autoscale based on metrics

  • Host Based Metrics
  • Guest Based Metrics
  • Application Based Metrics

https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-autoscale-overview

For creating autoscale rules via PowerShell you can find the available options here:

https://docs.microsoft.com/en-us/powershell/module/AzureRM.Insights/New-AzureRmAutoscaleRule?view=azurermps-6.13.0

All in all, you can create custom autoscale rules, however they need to be based on the current available metrics we provide not a custom metric. So I would suggest you find the best fit in the options listed in the above docs and use that metric to scale your VMSS.