安装并配置 Azure 诊断扩展 (WAD)Install and configure Azure diagnostics extension (WAD)

Azure 诊断扩展是 Azure Monitor 中的一个代理,可从 Azure 虚拟机的来宾操作系统和工作负载以及其他计算资源中收集监视数据。Azure diagnostics extension is an agent in Azure Monitor that collects monitoring data from the guest operating system and workloads of Azure virtual machines and other compute resources. 本文详细介绍如何安装并配置 Windows 诊断扩展,以及如何将数据存储在 Azure 存储帐户中。This article provides details on installing and configuring the Windows diagnostics extension and a description of how the data is stored in and Azure Storage account.

诊断扩展作为 Azure 中的虚拟机扩展实现,因此,它支持使用资源管理器模板、PowerShell 和 CLI 的相同安装选项。The diagnostics extension is implemented as a virtual machine extension in Azure, so it supports the same installation options using Resource Manager templates, PowerShell, and CLI. 有关安装和维护虚拟机扩展的详细信息,请参阅适用于 Windows 的虚拟机扩展和功能See Virtual machine extensions and features for Windows for details on installing and maintaining virtual machine extensions.

概述Overview

配置 Azure 诊断扩展时,必须指定一个存储帐户,所有指定的数据都将发送到该帐户。When you configure Azure the diagnostics extension, you must specify a storage account where all specified data will be sent.

使用 Azure 门户安装Install with Azure portal

你可以在 Azure 门户中的单个虚拟机上安装并配置诊断扩展,门户会提供一个界面,而不是直接让你进行配置。You can install and configure the diagnostics extension on an individual virtual machine in the Azure portal which provides you an interface as opposed to working directly with the configuration. 启用诊断扩展时,它会自动使用包含最常见性能计数器和事件的默认配置。When you enable the diagnostics extension, it will automatically use a default configuration with the most common performance counters and events. 可根据具体要求修改此默认配置。You can modify this default configuration according to your specific requirements.

备注

以下内容描述了诊断扩展的最常见设置。The following describe the most common settings for the diagnostics extension. 有关所有配置选项的详细信息,请参阅 Windows 诊断扩展架构For details on all of the configuration options, see Windows diagnostics extension schema.

  1. 在 Azure 门户中打开虚拟机的菜单。Open the menu for a virtual machine in the Azure portal.

  2. 在 VM 菜单的“监视”部分中单击“诊断设置” 。Click on Diagnostic settings in the Monitoring section of the VM menu.

  3. 如果尚未启用诊断扩展,请单击“启用来宾级监视”。Click Enable guest-level monitoring if the diagnostics extension hasn't already been enabled.

    启用监视

  4. 随后将为 VM 创建一个新的 Azure 存储帐户,其名称基于 VM 资源组的名称,并且将选择一组默认的来宾性能计数器和日志。A new Azure Storage account will be created for the VM with the name will be based on the name of the resource group for the VM, and a default set of guest performance counters and logs will be selected.

    诊断设置

  5. 在“性能计数器”选项卡中,选择要从此虚拟机收集的来宾指标。In the Performance counters tab, select the guest metrics you would like to collect from this virtual machine. 对于更高级的选择,请使用“自定义”设置。Use the Custom setting for more advanced selection.

    性能计数器

  6. 在“日志”选项卡中,选择要从虚拟机中收集的日志。In the Logs tab, select the logs to collect from the virtual machine. 可以将日志发送到存储或事件中心,但不能将其发送到 Azure Monitor。Logs can be sent to storage or event hubs, but not to Azure Monitor. 使用 Log Analytics 代理将来宾日志收集到 Azure Monitor。Use the Log Analytics agent to collect guest logs to Azure Monitor.

    屏幕截图显示为虚拟机选择了不同日志的“日志”选项卡。

  7. 在“故障转储”选项卡中,指定在发生故障后用于收集内存转储的任何进程。In the Crash dumps tab, specify any processes to collect memory dumps after a crash. 数据将写入到存储帐户以进行诊断设置,你可以选择指定 blob 容器。The data will be written to the storage account for the diagnostic setting, and you can optionally specify a blob container.

    故障转储

  8. 在“代理”中,可以更改存储帐户、设置磁盘配额,并指定是否收集诊断基础结构日志。In the Agent, you can change the storage account, set the disk quota, and specify whether to collect diagnostic infrastructure logs.

    屏幕截图显示“代理”选项卡,其中包含用于设置存储帐户的选项。

  9. 单击 保存 以保存配置。Click Save to save the configuration.

备注

尽管诊断扩展的配置可以采用 JSON 或 XML 格式,但在 Azure 门户中完成的任何配置始终以 JSON 格式存储。While the configuration for diagnostics extension can be formatted in either JSON or XML, any configuration done in the Azure portal will always be stored as JSON. 如果将 XML 与其他配置方法配合使用,然后使用 Azure 门户更改配置,则设置将更改为 JSON 格式。If you use XML with another configuration method and then change your configuration with the Azure portal, the settings will be changed to JSON.

Resource Manager 模板Resource Manager template

有关如何使用 Azure 资源管理器模板部署诊断扩展的信息,请参阅将监视和诊断与 Windows VM 和 Azure 资源管理器模板配合使用See Use monitoring and diagnostics with a Windows VM and Azure Resource Manager templates on deploying the diagnostics extension with Azure Resource Manager templates.

Azure CLI 部署Azure CLI deployment

可以在 Azure CLI 中使用 az vm extension set 将 Azure 诊断扩展部署到现有的虚拟机,如以下示例所示。The Azure CLI can be used to deploy the Azure Diagnostics extension to an existing virtual machine using az vm extension set as in the following example.

az vm extension set \
  --resource-group myResourceGroup \
  --vm-name myVM \
  --name IaaSDiagnostics \
  --publisher Microsoft.Azure.Diagnostics \
  --protected-settings protected-settings.json \
  --settings public-settings.json 

受保护的设置在配置架构的 PrivateConfig 元素中定义。The protected settings are defined in the PrivateConfig element of the configuration schema. 下面是用于定义存储帐户的受保护设置文件的极简示例。Following is a minimal example of a protected settings file that defines the storage account. 有关专用设置的完整详细信息,请参阅示例配置See Example configuration for complete details of the private settings.

{
    "storageAccountName": "mystorageaccount",
    "storageAccountKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "storageAccountEndPoint": "https://mystorageaccount.blob.core.chinacloudapi.cn"
}

公共设置在配置架构的 Public 元素中定义。The public settings are defined in the Public element of the configuration schema. 下面是公共设置文件的极简示例,该示例启用诊断基础结构日志、单个性能计数器和单个事件日志的集合。Following is a minimal example of a public settings file that enables collection of diagnostic infrastructure logs, a single performance counter, and a single event log. 有关公共设置的完整详细信息,请参阅示例配置See Example configuration for complete details of the public settings.

{
  "StorageAccount": "mystorageaccount",
  "WadCfg": {
    "DiagnosticMonitorConfiguration": {
      "overallQuotaInMB": 5120,
      "PerformanceCounters": {
        "scheduledTransferPeriod": "PT1M",
        "PerformanceCounterConfiguration": [
          {
            "counterSpecifier": "\\Processor Information(_Total)\\% Processor Time",
            "unit": "Percent",
            "sampleRate": "PT60S"
          }
        ]
      },
      "WindowsEventLog": {
        "scheduledTransferPeriod": "PT1M",
        "DataSource": [
          {
            "name": "Application!*[System[(Level=1 or Level=2 or Level=3)]]"
          }
        ]
      }
    }
  }
}

PowerShell 部署PowerShell deployment

可以在 PowerShell 中使用 Set-AzVMDiagnosticsExtension 将 Azure 诊断扩展部署到现有的虚拟机,如以下示例所示。PowerShell can be used to deploy the Azure Diagnostics extension to an existing virtual machine using Set-AzVMDiagnosticsExtension as in the following example.

Set-AzVMDiagnosticsExtension -ResourceGroupName "myvmresourcegroup" `
  -VMName "myvm" `
  -DiagnosticsConfigurationPath "DiagnosticsConfiguration.json"

专用设置在 PrivateConfig 元素中定义,公共设置在配置架构的 Public 元素中定义。The private settings are defined in the PrivateConfig element, while the public settings are defined in the Public element of the configuration schema. 还可以选择将存储帐户详细信息指定为 Set-AzVMDiagnosticsExtension cmdlet 的参数,而无需在专用设置中包含这些信息。You can also choose to specify the details of the storage account as parameters of the Set-AzVMDiagnosticsExtension cmdlet rather than including them in the private settings.

下面是配置文件的极简示例,该示例启用诊断基础结构日志、单个性能计数器和单个事件日志的集合。Following is a minimal example of a configuration file that enables collection of diagnostic infrastructure logs, a single performance counter, and a single event log. 有关专用设置和公共设置的完整详细信息,请参阅示例配置See Example configuration for complete details of the private and public settings.

{
    "PublicConfig": {
        "WadCfg": {
            "DiagnosticMonitorConfiguration": {
                "overallQuotaInMB": 10000,
                "DiagnosticInfrastructureLogs": {
                    "scheduledTransferLogLevelFilter": "Error"
                },
                "PerformanceCounters": {
                    "scheduledTransferPeriod": "PT1M",
                    "PerformanceCounterConfiguration": [
                        {
                            "counterSpecifier": "\\Processor(_Total)\\% Processor Time",
                            "sampleRate": "PT3M",
                            "unit": "percent"
                        }
                    ]
                },
                "WindowsEventLog": {
                    "scheduledTransferPeriod": "PT1M",
                        "DataSource": [
                        {
                            "name": "Application!*[System[(Level=1 or Level=2 or Level=3)]]"
                        }
                    ]
                }
            }
        },
        "StorageAccount": "mystorageaccount",
        "StorageType": "TableAndBlob"
    },
    "PrivateConfig": {
        "storageAccountName": "mystorageaccount",
        "storageAccountKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "storageAccountEndPoint": "https://mystorageaccount.blob.core.chinacloudapi.cn"
    }
}

另请参阅使用 PowerShell 在运行 Windows 的虚拟机中启用 Azure 诊断See also Use PowerShell to enable Azure Diagnostics in a virtual machine running Windows.

数据存储Data storage

下表列出了从诊断扩展收集的不同数据类型,以及这些数据是以表还是 blob 的形式存储。The following table lists the different types of data collected from the diagnostics extension and whether they're stored as a table or a blob. 表中存储的数据还可以根据公共配置中的 StorageType 设置存储在 blob 中。The data stored in tables can also be stored in blobs depending on the StorageType setting in your public configuration.

数据Data 存储类型Storage type 说明Description
WADDiagnosticInfrastructureLogsTableWADDiagnosticInfrastructureLogsTable Table 诊断监视器和配置更改。Diagnostic monitor and configuration changes.
WADDirectoriesTableWADDirectoriesTable Table 诊断监视器正在监视的目录。Directories that the diagnostic monitor is monitoring. 这包括 IIS 日志、IIS 失败请求日志和自定义目录。This includes IIS logs, IIS failed request logs, and custom directories. 在“容器”字段中指定 blob 日志文件的位置,在 RelativePath 字段中指定 blob 的名称。The location of the blob log file is specified in the Container field and the name of the blob is in the RelativePath field. AbsolutePath 字段指示文件的位置和名称,就像文件是存在于 Azure 虚拟机上一样。The AbsolutePath field indicates the location and name of the file as it existed on the Azure virtual machine.
WadLogsTableWadLogsTable Table 使用跟踪侦听器在代码中写入的日志。Logs written in code using the trace listener.
WADPerformanceCountersTableWADPerformanceCountersTable Table 性能计数器。Performance counters.
WADWindowsEventLogsTableWADWindowsEventLogsTable Table Windows 事件日志。Windows Event logs.
wad-iis-failedreqlogfileswad-iis-failedreqlogfiles BlobBlob 包含 IIS 失败请求日志中的信息。Contains information from IIS Failed Request logs.
wad-iis-logfileswad-iis-logfiles BlobBlob 包含有关 IIS 日志的信息。Contains information about IIS logs.
"custom""custom" BlobBlob 一个自定义容器,该容器取决于诊断监视器所监视的配置目录。A custom container based on configuring directories that are monitored by the diagnostic monitor. 此 blob 容器的名称会在 WADDirectoriesTable 中指定。The name of this blob container will be specified in WADDirectoriesTable.

用于查看诊断数据的工具Tools to view diagnostic data

将数据传输到存储空间以后,可以使用多个工具来查看这些数据。Several tools are available to view the data after it is transferred to storage. 例如:For example:

  • Visual Studio 中的服务器资源管理器 - 如果安装了 Azure Tools for Microsoft Visual Studio,则可以在服务器资源管理器中使用“Azure 存储”节点从 Azure 存储帐户查看只读 Blob 和表数据。Server Explorer in Visual Studio - If you have installed the Azure Tools for Microsoft Visual Studio, you can use the Azure Storage node in Server Explorer to view read-only blob and table data from your Azure storage accounts. 既可以从本地存储模拟器帐户显示数据,也可以从为 Azure 创建的存储帐户显示数据。You can display data from your local storage emulator account and also from storage accounts you have created for Azure. 有关详细信息,请参阅使用服务器资源管理器浏览和管理存储资源For more information, see Browsing and Managing Storage Resources with Server Explorer.
  • Azure 存储资源管理器是一款独立应用,可用于在 Windows、OSX 和 Linux 上轻松处理 Azure 存储数据。Azure Storage Explorer is a standalone app that enables you to easily work with Azure Storage data on Windows, OSX, and Linux.
  • Azure Management Studio 包括 Azure 诊断管理器,该诊断管理器用于查看、下载和管理在 Azure 上运行的应用程序收集的诊断数据。Azure Management Studio includes Azure Diagnostics Manager which allows you to view, download and manage the diagnostics data collected by the applications running on Azure.

后续步骤Next steps