az vm diagnostics

Configure the Azure Virtual Machine diagnostics extension.

Commands

Name Description Type Status
az vm diagnostics get-default-config

Get the default configuration settings for a VM.

Core GA
az vm diagnostics set

Configure the Azure VM diagnostics extension.

Core GA

az vm diagnostics get-default-config

Get the default configuration settings for a VM.

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

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.

Default value: False
Global Parameters
--debug

Increase logging verbosity to show all debug logs.

--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

--output -o

Output format.

Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
Default value: json
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

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

--verbose

Increase logging verbosity. Use --debug for full debug logs.

az vm diagnostics set

Configure the Azure VM diagnostics extension.

az vm diagnostics set --settings
                      [--ids]
                      [--no-auto-upgrade {false, true}]
                      [--no-auto-upgrade-minor-version {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). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--no-auto-upgrade
Deprecated

Option '--no-auto-upgrade' has been deprecated and will be removed in a future release. Use '--no-auto-upgrade-minor-version' instead.

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
Default value: False
--no-auto-upgrade-minor-version

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
Default value: False
--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>.

Global Parameters
--debug

Increase logging verbosity to show all debug logs.

--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

--output -o

Output format.

Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
Default value: json
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

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

--verbose

Increase logging verbosity. Use --debug for full debug logs.