你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

从 Azure 负载测试导出测试结果,以供在第三方工具中使用

本文介绍如何导出 Azure 负载测试测试结果。 可以使用 Azure 门户、作为 CI/CD 工作流中的项目、使用后端侦听器在 JMeter 中或通过从 Azure 存储帐户复制结果来下载结果。 可将这些结果用于在第三方工具中进行报告或用于诊断测试失败。 Azure 负载测试以逗号分隔值 (CSV) 文件格式生成测试结果,并提供负载测试的每个应用程序请求的详细信息。

你还可以使用测试结果在负载测试期间诊断错误。 responseCoderesponseMessage 字段详细提供了有关失败请求的信息。 有关调查错误的详细信息,请参阅诊断失败的负载测试

你可以按照此处提到的步骤从 CSV 日志文件生成 Apache JMeter 仪表板。

先决条件

  • 具有活动订阅的 Azure 帐户。 如果没有 Azure 订阅,请在开始之前创建一个免费帐户
  • 已完成测试运行的 Azure 负载测试资源。 如果需要创建 Azure 负载测试资源,请参阅创建并运行负载测试

测试结果文件格式

Azure 负载测试为每个测试引擎实例生成一个测试结果 CSV 文件。 了解如何横向扩展负载测试

Azure 负载测试使用 Apache JMeter CSV 日志格式。 有关不同字段的详细信息,请参阅 Apache JMeter 文档中的 JMeter 术语表

可以在测试结果文件中找到负载测试运行的每个应用程序请求的详细信息。 以下代码片段演示一个示例测试结果:

timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1676040230680,104,Homepage,200,OK,172.18.33.7-Thread Group 1-5,text,true,,1607,133,5,5,https://www.example.com/,104,0,100
1676040230681,101,Homepage,200,OK,172.18.33.7-Thread Group 1-3,text,true,,1591,133,5,5,https://www.example.com/,101,0,93
1676040230680,101,Homepage,200,OK,172.18.33.7-Thread Group 1-1,text,true,,1591,133,5,5,https://www.example.com/,98,0,94

访问和下载负载测试结果

负载测试运行完成后,可以通过 Azure 门户或作为 CI/CD 工作流中的项目访问和下载负载测试结果。

重要

如果负载测试的引擎实例超过 45 个或测试运行时间超过 3 小时,则无法下载结果文件。 可以配置 JMeter 后端侦听器以导出结果到你选择的数据存储或从存储帐户容器复制结果

若要在 Azure 门户中下载测试运行的测试结果,请执行以下操作:

  1. Azure 门户中,转到 Azure 负载测试资源。

  2. 在左窗格中,选择“测试”以查看测试列表,然后选择测试

    Screenshot that shows the list of tests for an Azure Load Testing resource.

    提示

    若要限制要在列表中显示的测试数,可使用搜索框和“时间范围”筛选器

  3. 可以通过以下两种方式之一将测试结果文件下载为压缩文件夹:

    • 选择使用的负载测试运行旁边的省略号 (...),然后选择“下载结果文件”

      Screenshot that shows how to download the results file for a load test run.

      注意

      负载测试运行需要具有“完成”、“已停止”或“失败”状态,结果文件才可供下载

    • 在“测试运行详细信息”窗格中,选择“下载”,然后选择“结果”

      Screenshot that shows how to download the test results from the 'Test run details' pane.

  4. 可以使用任何 zip 工具提取文件夹并访问测试结果。

    Screenshot that shows the test results zip file in the downloads list.

    该文件夹包含每个测试引擎的单独 CSV 文件,并包含测试引擎在负载测试期间执行的请求的详细信息。

使用 JMeter 后端侦听器导出测试结果

可以使用 JMeter 后端侦听器将测试结果导出到 InfluxDB、MySQL 等数据库或 Azure Application Insights 等监视工具。

可以使用默认的 JMeter 后端侦听器、来自 jmeter-plugins.org 的后端侦听器或采用 Java 存档 (JAR) 文件形式的自定义后端侦听器。

以下代码片段演示如何在 JMeter 文件 (JMX) 中使用 Azure Application Insights 的后端侦听器的示例:

<BackendListener guiclass="BackendListenerGui" testclass="BackendListener" testname="Backend Listener" enabled="true">
  <elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" enabled="true">
    <collectionProp name="Arguments.arguments">
      <elementProp name="testName" elementType="Argument">
        <stringProp name="Argument.name">testName</stringProp>
        <stringProp name="Argument.value">jmeter</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="connectionString" elementType="Argument">
        <stringProp name="Argument.name">connectionString</stringProp>
        <stringProp name="Argument.value">Enter your AppInsights connection string</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="liveMetrics" elementType="Argument">
        <stringProp name="Argument.name">liveMetrics</stringProp>
        <stringProp name="Argument.value">true</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="samplersList" elementType="Argument">
        <stringProp name="Argument.name">samplersList</stringProp>
        <stringProp name="Argument.value"></stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="useRegexForSamplerList" elementType="Argument">
        <stringProp name="Argument.name">useRegexForSamplerList</stringProp>
        <stringProp name="Argument.value">false</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="logResponseData" elementType="Argument">
        <stringProp name="Argument.name">logResponseData</stringProp>
        <stringProp name="Argument.value">OnFailure</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="logSampleData" elementType="Argument">
        <stringProp name="Argument.name">logSampleData</stringProp>
        <stringProp name="Argument.value">OnFailure</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
    </collectionProp>
  </elementProp>
  <stringProp name="classname">io.github.adrianmo.jmeter.backendlistener.azure.AzureBackendClient</stringProp>
</BackendListener>

可以下载使用 Azure Application Insights 后端侦听器的完整示例

从存储帐户容器复制测试项目

重要

仅当负载测试的引擎实例超过 45 个或测试运行持续时间超过三小时,才会启用从存储帐户容器复制测试项目。

若要从存储帐户复制测试运行的测试结果和日志文件,请在 Azure 门户中:

  1. Azure 门户中,转到 Azure 负载测试资源。

  2. 在左窗格中,选择“测试”以查看测试列表,然后选择测试

    Screenshot that shows the list of tests for an Azure Load Testing resource.

  3. 从测试运行列表中选择测试运行。

    Screenshot that shows the list of test runs for a test in an Azure Load Testing resource.

    提示

    若要限制要在列表中显示的测试数,可使用搜索框和“时间范围”筛选器

  4. 在“测试运行详细信息”窗格中,选择“复制项目”

    Screenshot that shows how to copy the test artifacts from the 'Test run details' pane.

    注意

    负载测试运行需要处于“完成”、“已停止”或“失败”状态,结果文件才可供下载

  5. 复制存储帐户容器的 SAS URL。

    可以使用 Azure 存储资源管理器AzCopy 中的 SAS URL 将测试运行的结果 CSV 文件和日志文件复制到存储帐户。

    SAS URL 自生成起 60 分钟内有效。 如果 URL 过期,请选择“复制项目”以生成新的 SAS URL