Below is the solution offered by Microsoft
Once the VMSS is set. You can follow the below instruction on how to set up autoscale to scale VMSS on memory
Install the IaaSDiagnostics extension at the VMSS level
- The first thing that we have to do is add the diagnostics extension to the VMSS. This is the easiest from Azure CLI, because we have a command to pull the default config of the extension schema:
$ az vmss diagnostics get-default-config --is-windows-os > <where you want the file stored locally>\config.json //if you are installing on Linux, remove --is-windows-os
Example:
$ az vmss diagnostics get-default-config --is-windows-os > C:\diagnostic\config.json
There will be output in your CLI or PowerShell window. Copy the following output for later:
{
"storageAccountName": "STORAGE_ACCOUNT_NAME",
"storageAccountSasToken": "SAS_TOKEN_WITH_LEADING_QUESTION_MARK"
}
- Make sure that your config.json file ended up where you wanted it to go, and open it. There are two lines in here that we need to fill in with our information:
"StorageAccount": "DIAGNOSTIC_STORAGE_ACCOUNT", and
"resourceId": "VM_OR_VMSS_RESOURCE_ID"
- Save the config.json file,
- we need to create our protected settings file. In the same directory where our config.json file is
- create a new txt file and name it protected-settings.txt. Add the json block that we copied from CLI or PowerShell earlier:
Fill in the information, and then save the file as protected-settings.json.
{
"storageAccountName": "STORAGE_ACCOUNT_NAME",
"storageAccountSasToken": "SAS_TOKEN_WITH_LEADING_QUESTION_MARK"
} - We need to add extension. Open the powershell / CLI
$ az vmss diagnostics set --resource-group <vmss RG> --vmss-name <vmss name> --settings <directory of config file>\config.json --protected-settings <directory of protected settings file>\protected-settings.json
Example:
$ az vmss diagnostics set --resource-group memscale --vmss-name memscalevmss --settings C:\diagnostic\config.json --protected-settings C:\diagnostic\protected-settings.json - make sure that you update your VMSS if its set to manual:
$ az vmss update-instances --resource-group <vmss RG> --name <vmss name> --instance-ids "*"
Now, you can either check that the extension is on the VMSS in the Portal or through CLI. If you choose CLI, the command is:
$ az vmss show --resource-group <vmss RG> --name <vmss name>
Checking through the Portal is as easy as looking at the extensions in the VMSS blade. - To confirm that the metrics are being collected, make sure that the VMSS is running and has been for a while, and check the diagnostic storage account --> table storage. You should see the following there (among others):
o WADDiagnosticInfrastructureLogsTable
o WADMetricsPT1MP10DV2S<date>
o WADPerformanceCountersTable
Creating the autoscale rules on the VMSS
To create autoscale rules based on the IaaSDiagnostics extension that we added earlier, follow these steps:
· On the VMSS blade, click Scaling
· Change over to custom autoscale
· Click + Add Rule
· Change the Metric namespace to Guest (Classic)
· Select Memory Usage in the Metric name field
· Fill in your percentages
· Depending on what you want your rules to do, fill in the rest of the fields
· Don't forget to create another rule for scaling back in
Save your new autoscale rules, and then update your current VMSS instances, if your upgrade policy is set to manual.