az vm diagnostics

設定 Azure 虛擬機器診斷擴充功能。

命令

名稱 Description 類型 狀態
az vm diagnostics get-default-config

取得 VM 的預設組態設定。

核心 GA
az vm diagnostics set

設定 Azure VM 診斷擴充功能。

核心 GA

az vm diagnostics get-default-config

取得 VM 的預設組態設定。

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

範例

取得 Linux VM 的預設診斷,並覆寫儲存體帳戶名稱和 VM 資源識別碼。

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

取得 Windows VM 的預設診斷。

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

選擇性參數

--is-windows-os

針對 Windows VM。

預設值: False
全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az vm diagnostics set

設定 Azure VM 診斷擴充功能。

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]

範例

在適用于 Azure 入口網站 VM 計量圖表和 syslog 集合的 Linux VM 上設定預設診斷。

# 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

在 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'}"

必要參數

--settings

Json 字串或檔案路徑,定義要收集的資料。

選擇性參數

--ids

一或多個資源識別碼 (以空格分隔)。 它應該是包含 「資源識別碼」引數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」引數。

--no-auto-upgrade
已被取代

選項 '--no-auto-upgrade' 已被取代,將在未來的版本中移除。 請改用 '--no-auto-upgrade-minor-version'。

如果設定,即使重新部署擴充功能,擴充服務也不會自動挑選或升級至最新的次要版本。

接受的值: false, true
預設值: False
--no-auto-upgrade-minor-version

如果設定,即使重新部署擴充功能,擴充服務也不會自動挑選或升級至最新的次要版本。

接受的值: false, true
預設值: False
--protected-settings

Json 字串或包含私人組態的檔案路徑,例如儲存體帳戶金鑰等。

--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--version

診斷擴充功能的版本。 若未指定,則會使用最新的 。

--vm-name

虛擬機器的名稱。 您可以使用 來設定預設值 az configure --defaults vm=<name>

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。