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