There are some options to create a Virtual Machine Scale Set with the diagnostics extension to perform in-guest monitoring and collect metrics from inside your virtual machines.
On the other hand, if you have an existing Virtual Machine Scale Set without such extension, there’s a way to enable them. This is what I’ll show in this post in a detailed way explaining how to configure each one of the parameters required.
How do I know if I have diagnostics extension deployed or not?
The first thing to notice if you are looking to monitor your guest VMs in a VM Scale Set is if you already have the extension deployed or not. This is easy to be accomplished by going to the VMSS page in the Azure Portal and clicking on Metrics. If there are no metrics available in the Guest section this means there’s no diagnostic extension installed and only metrics provided at the Host level, captured by the virtualization layer are available. The picture bellow shows this scenario:
:format(jpg):extract_cover()/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1638%2F1*mu8MkBc4peqsnpMJjr4cpA.png)
So, as there’s no Guest metrics available, we can conclude that the extension is not installed and we can install it.
Storage Account
To hold diagnostics data we need a storage account provisioned, you can provision a new storage account or use an existing one.
Getting the Default Config
The first step to work with Azure VM Scale Set diagnostics is to get the default config. This is a template file we use to enable the diagnostics extension and also we can customize it to fit our needs.
You can run the following command to get the VMSS diagnostic config file and send it to a file named config.json:
az vmss diagnostics get-default-config > config.json
You will notice that a config.json file will be generated in the current folder while another JSON will be output to the screen as shown bellow.
:format(jpg):extract_cover()/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1880%2F1*GpffsID09J6NSPDu1jj4GQ.png)
Copy this JSON as it will be the one you will use to put protected data like the Storage Account SAS Token and place it in a file called protected-settings.json. We will use both files.
Fill the protected-settings.json with the storage account information. In the storageAccountName field, enter the name of the storage account you provisioned to hold diagnostics data and in the storageAccountSasToken enter a SAS token you can generate in the storage account in the Shared access signature section. Just make sure you don’t include the question mark. Also make sure you select a large time frame for the token or you will have to update it later as by default it is valid for just a few hours.
The resulting config will look like the following: