VM diagnostics - az vm diagnostics

Configure the Azure Virtual Machine diagnostics extension.

Commands

az vm diagnostics get-default-config Show the default config file which defines data to be collected.
az vm diagnostics set Configure the Azure VM diagnostics extension.

az vm diagnostics get-default-config

Show the default config file which defines data to be collected.

az vm diagnostics get-default-config [--is-windows-os]

Examples

Get the default diagnostics on a Linux VM and override the storage account name and the VM resource ID.

az vm diagnostics get-default-config     | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#MyStorageAccount#g"     | sed "s#__VM_OR_VMSS_RESOURCE_ID__#MyVmResourceId#g"

Get the default diagnostics on a Windows VM.

az vm diagnostics get-default-config --is-windows-os

Optional Parameters

--is-windows-os

az vm diagnostics set

Configure the Azure VM diagnostics extension.

az vm diagnostics set --resource-group
--settings
--vm-name
[--no-auto-upgrade]
[--protected-settings]
[--version]

Examples

Set up default diagnostics on a Linux VM for Azure Portal VM metrics graphs and syslog collection.

# Set the following 3 parameters correctly first.
                        my_resource_group=
                        my_linux_vm=
                        my_diagnostic_storage_account=
                        
                        my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_linux_vm --query "id" -o tsv)
                        
                        default_config=$(az vm diagnostics get-default-config     | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g"     | sed "s#__VM_OR_VMSS_RESOURCE_ID__#$my_vm_resource_id#g")
                        
                        storage_sastoken=$(az storage account generate-sas     --account-name $my_diagnostic_storage_account --expiry 9999-12-31T23:59Z     --permissions wlacu --resource-types co --services bt -o tsv)
                        
                        protected_settings="{'storageAccountName': '${my_diagnostic_storage_account}',     'storageAccountSasToken': '${storage_sastoken}'}"
                        
                        az vm diagnostics set --settings "${default_config}"     --protected-settings "${protected_settings}"     --resource-group $my_resource_group --vm-name $my_linux_vm

Required Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

--settings

Json string or a file path, which defines data to be collected.

--vm-name

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=.

Optional Parameters

--no-auto-upgrade

By doing this, extension system will not pick the highest minor version for the specified version number, and will not auto update to the latest build/revision number on any scale set updates in future.

--protected-settings

Json string or a file path containing private configurations such as storage account keys, etc.

--version

Version of the diagnostics extension. Will use the latest if not specfied.