适用于 Windows 的 Azure 性能诊断 VM 扩展

Azure 性能诊断 VM 扩展可帮助从 Windows VM 收集性能诊断数据。 扩展执行分析,并提供发现和建议的报告,以识别和解决虚拟机上的性能问题。 此扩展安装名为 PerfInsights 的故障排除工具。

注意

如果要从非经典 VM 的Azure 门户在 VM 上运行诊断,建议使用新体验。 有关详细信息,请参阅 Azure 虚拟机的性能诊断

先决条件

可以在以下位置安装此扩展:

  • Windows Server 2019
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2012
  • Windows Server 2008 R2
  • Windows 10
  • Windows 8.1
  • Windows 8

扩展架构

以下 JSON 显示了 Azure 性能诊断 VM 扩展的架构。 此扩展需要存储帐户的名称和密钥来存储诊断输出和报表。 这些值是敏感的。 存储帐户密钥应存储在受保护的设置配置中。 Azure VM 扩展保护的设置数据已加密,并且仅在目标虚拟机上解密。 请注意, storageAccountNamestorageAccountKey 区分大小写。 以下部分列出了其他必需的参数。

    {
      "name": "[concat(parameters('vmName'),'/AzurePerformanceDiagnostics')]",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "location": "[parameters('location')]",
      "apiVersion": "2015-06-15",
      "properties": {
        "publisher": "Microsoft.Azure.Performance.Diagnostics",
        "type": "AzurePerformanceDiagnostics",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "storageAccountName": "[parameters('storageAccountName')]",
          "performanceScenario": "[parameters('performanceScenario')]",
          "traceDurationInSeconds": "[parameter('traceDurationInSeconds')]",
          "perfCounterTrace": "[parameters('perfCounterTrace')]",
          "networkTrace": "[parameters('networkTrace')]",
          "xperfTrace": "[parameters('xperfTrace')]",
          "storPortTrace": "[parameters('storPortTrace')]",
          "srNumber": "[parameters('srNumber')]",
          "requestTimeUtc":  "[parameters('requestTimeUtc')]",
          "resourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
        },
        "protectedSettings": {
            "storageAccountKey": "[parameters('storageAccountKey')]"        
        }
      }
    }

属性值

名称 值/示例 说明
apiVersion 2015-06-15 API 的版本。
发布者 Microsoft.Azure.Performance.Diagnostics 扩展的发布者命名空间。
type AzurePerformanceDiagnostics VM 扩展的类型。
typeHandlerVersion 1.0 扩展处理程序的版本。
performanceScenario 基本 要捕获数据的性能方案。 有效值为: basicvmslowazurefilescustom
traceDurationInSeconds 300 如果已选择任何跟踪选项,则跟踪的持续时间。
perfCounterTrace p 用于启用性能计数器跟踪的选项。 有效值为 p 或空值。 如果不想捕获此跟踪,请将值保留为空。
networkTrace n 启用网络跟踪的选项。 有效值为 n 或空值。 如果不想捕获此跟踪,请将值保留为空。
xperfTrace x 用于启用 XPerf 跟踪的选项。 有效值为 x 或空值。 如果不想捕获此跟踪,请将值保留为空。
storPortTrace s 用于启用 StorPort 跟踪的选项。 有效值为 s 或空值。 如果不想捕获此跟踪,请将值保留为空。
srNumber 123452016365929 支持票证编号(如果可用)。 如果没有该值,请将该值保留为空。
requestTimeUtc 2017-09-28T22:08:53.736Z 当前日期时间(以 Utc 为单位)。 如果使用门户安装此扩展,则无需提供此值。
resourceId /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} VM 的唯一标识符。
storageAccountName mystorageaccount 用于存储诊断日志和结果的存储帐户的名称。
storageAccountKey lDuVvxuZB28NNP...hAiRF3voADxLBTcc== 存储帐户的密钥。

安装扩展

按照以下说明在 Windows 虚拟机上安装扩展:

  1. 登录 Azure 门户

  2. 选择要安装此扩展的虚拟机。

    Azure 门户的屏幕截图,其中突出显示了“虚拟机”。

  3. 选择“ 扩展 + 应用程序 ”边栏选项卡,然后选择“ 添加”。

    “扩展”边栏选项卡的屏幕截图,其中突出显示了“添加”。

  4. 搜索 Azure 性能诊断,单击扩展,查看条款和条件,然后选择“下一步”。

    “新建资源”屏幕的屏幕截图,其中突出显示了“Azure 性能诊断”。

  5. 提供安装的参数值,然后安装扩展。 有关受支持方案的详细信息,请参阅 如何使用 PerfInsights

    “安装扩展”对话框的屏幕截图。

  6. 安装成功后,扩展的状态将显示 “预配成功”。

    预配成功消息的屏幕截图。

    注意

    预配成功后,扩展将运行。 基本方案需要两分钟或更短的时间才能完成。 对于其他方案,它会在安装期间指定的持续时间内运行。

删除扩展

若要从虚拟机中删除扩展,请执行以下步骤:

  1. 登录到Azure 门户,选择要从中删除此扩展的虚拟机,然后选择“扩展 + 应用程序”边栏选项卡。

  2. 选择“性能诊断扩展”,然后选择“ 卸载”。

    “扩展”边栏选项卡的屏幕截图,其中突出显示了“卸载”。

模板部署

可以使用 Azure 资源管理器模板部署 Azure 虚拟机扩展。 上一部分详述的 JSON 架构可以在 Azure 资源管理器模板中使用。 这会在 Azure 资源管理器 模板部署期间运行 Azure 性能诊断 VM 扩展。 下面是一个示例模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string",
      "defaultValue": "yourVMName"
    },
    "location": {
      "type": "string",
      "defaultValue": "southcentralus"
    },
    "storageAccountName": {
      "type": "securestring",
      "defaultValue": "yourStorageAccount"
    },
    "storageAccountKey": {
      "type": "securestring",
      "defaultValue": "yourStorageAccountKey"
    },
    "performanceScenario": {
      "type": "string",
      "defaultValue": "basic"
    },
    "srNumber": {
      "type": "string",
      "defaultValue": ""
    },
  "traceDurationInSeconds": {
    "type": "int",
    "defaultValue": 300
  },
    "perfCounterTrace": {
      "type": "string",
      "defaultValue": "p"
    },
    "networkTrace": {
      "type": "string",
      "defaultValue": ""
    },
    "xperfTrace": {
      "type": "string",
      "defaultValue": ""
    },
    "storPortTrace": {
      "type": "string",
      "defaultValue": ""
    },
    "requestTimeUtc": {
      "type": "string",
      "defaultValue": "10/2/2017 11:06:00 PM"
    }        
  },
  "resources": [
    {
      "name": "[concat(parameters('vmName'),'/AzurePerformanceDiagnostics')]",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "location": "[parameters('location')]",
      "apiVersion": "2015-06-15",
      "properties": {
        "publisher": "Microsoft.Azure.Performance.Diagnostics",
        "type": "AzurePerformanceDiagnostics",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "storageAccountName": "[parameters('storageAccountName')]",
          "performanceScenario": "[parameters('performanceScenario')]",
          "traceDurationInSeconds": "[parameters('traceDurationInSeconds')]",
          "perfCounterTrace": "[parameters('perfCounterTrace')]",
          "networkTrace": "[parameters('networkTrace')]",
          "xperfTrace": "[parameters('xperfTrace')]",
          "storPortTrace": "[parameters('storPortTrace')]",
          "srNumber": "[parameters('srNumber')]",
          "requestTimeUtc":  "[parameters('requestTimeUtc')]",
          "resourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
        },
        "protectedSettings": {
            "storageAccountKey": "[parameters('storageAccountKey')]"
        }
      }
    }
  ]
}

PowerShell 部署

命令 Set-AzVMExtension 可用于将 Azure 性能诊断 VM 扩展部署到现有虚拟机。

$PublicSettings = @{ "storageAccountName"="mystorageaccount";"performanceScenario"="basic";"traceDurationInSeconds"=300;"perfCounterTrace"="p";"networkTrace"="";"xperfTrace"="";"storPortTrace"="";"srNumber"="";"requestTimeUtc"="2017-09-28T22:08:53.736Z";"resourceId"="VMResourceId" }
$ProtectedSettings = @{"storageAccountKey"="mystoragekey" }

Set-AzVMExtension -ExtensionName "AzurePerformanceDiagnostics" `
    -ResourceGroupName "myResourceGroup" `
    -VMName "myVM" `
    -Publisher "Microsoft.Azure.Performance.Diagnostics" `
    -ExtensionType "AzurePerformanceDiagnostics" `
    -TypeHandlerVersion 1.0 `
    -Settings $PublicSettings `
    -ProtectedSettings $ProtectedSettings `
    -Location WestUS

有关捕获的数据的信息

PerfInsights 工具收集各种日志、配置和诊断数据,具体取决于所选方案。 有关详细信息,请参阅 PerfInsights 文档

查看和共享结果

可以在上传到安装期间指定的存储帐户的 zip 文件中找到扩展的输出,并使用 共享访问签名 (SAS) 共享 30 天。 此 zip 文件包含诊断日志以及包含发现和建议的报告。 在文件夹 C:\Packages\Plugins\Microsoft.Azure.Performance.Diagnostics.AzurePerformanceDiagnostics<\version> 下,可以在名为 zipfilename_saslink.txt 的文本文件中找到指向输出 zip 文件的 SAS 链接。 具有此链接的任何人都可以下载 zip 文件。

为了协助支持工程师处理支持票证,Microsoft 可能会使用此 SAS 链接下载诊断数据。

若要查看报表,请提取 zip 文件并打开 PerfInsights Report.html 文件。

还应能够通过选择扩展名直接从门户下载 zip 文件。

性能诊断详细状态和扩展下载链接的屏幕截图。

注意

门户中显示的 SAS 链接有时可能不起作用。 这可能是由编码和解码操作期间格式不正确的 URL 引起的。 可以改为直接从 VM 中的 *_saslink.txt 文件获取链接。

故障排除和支持

  • 通知区域中的扩展部署状态 () 可能会显示“部署正在进行”,即使已成功预配扩展也是如此。

    只要扩展状态指示已成功预配扩展,就可以安全地忽略此问题。

  • 可以使用扩展日志解决安装过程中的一些问题。 扩展执行输出记录到以下目录中找到的文件:

    C:\WindowsAzure\Logs\Plugins\Microsoft.Azure.Performance.Diagnostics.AzurePerformanceDiagnostics\<version>

联系我们寻求帮助

如果你有任何疑问或需要帮助,请创建支持请求联系 Azure 社区支持。 还可以向 Azure 反馈社区提交产品反馈。