az vm diagnostics

Configure the Azure Virtual Machine diagnostics extension.

Commands

az vm diagnostics get-default-config Get the default configuration settings for a VM.
az vm diagnostics set Configure the Azure VM diagnostics extension.

az vm diagnostics get-default-config

Get the default configuration settings for a VM.

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

Examples

Get the default diagnostics for 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 for a Windows VM.

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

Optional Parameters

--is-windows-os

For Windows VMs.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm diagnostics set

Configure the Azure VM diagnostics extension.

az vm diagnostics set --settings
[--ids]
[--no-auto-upgrade {false, true}]
[--protected-settings]
[--resource-group]
[--subscription]
[--version]
[--vm-name]

Examples

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

# Set the following 3 parameters first.
my_resource_group={Resource group name containing your Linux VM and the storage account}
my_linux_vm={Your Azure Linux VM name}
my_diagnostic_storage_account={Your Azure storage account for storing VM diagnostic data}

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 2037-12-31T23:59:00Z \
    --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

Set up default diagnostics on a Windows VM.

# Set the following 3 parameters first.
my_resource_group={Resource group name containing your Windows VM and the storage account}
my_windows_vm={Your Azure Windows VM name}
my_diagnostic_storage_account={Your Azure storage account for storing VM diagnostic data}

my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_windows_vm --query "id" -o tsv)

default_config=$(az vm diagnostics get-default-config  --is-windows-os \
    | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g" \
    | sed "s#__VM_OR_VMSS_RESOURCE_ID__#$my_vm_resource_id#g")

# Please use the same options, the WAD diagnostic extension has strict
# expectations of the sas token's format. Set the expiry as desired.
storage_sastoken=$(az storage account generate-sas \
    --account-name $my_diagnostic_storage_account --expiry 2037-12-31T23:59:00Z \
    --permissions acuw --resource-types co --services bt --https-only --output 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_windows_vm

# # Alternatively, if the WAD extension has issues parsing the sas token,
# # one can use a storage account key instead.
storage_account_key=$(az storage account keys list --account-name {my_storage_account} \
  --query [0].value -o tsv)
protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \
  'storageAccountKey': '$storage_account_key'}"

Required Parameters

--settings

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

Optional Parameters

--ids

One or more resource IDs (space-delimited). If provided, no other 'Resource Id' arguments should be specified.

--no-auto-upgrade

If set, the extension service will not automatically pick or upgrade to the latest minor version, even if the extension is redeployed.

accepted values: false, true
--protected-settings

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

--resource-group -g

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

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--version

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

--vm-name

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