laitimes

使用 Apache JMeter Flexible File Writer 插件的详细指南

author:Tester: Mueller
使用 Apache JMeter Flexible File Writer 插件的详细指南

Brief introduction

Apache JMeter is a powerful open-source tool that is widely used for performance testing and load testing. In order to better record and analyze test results, JMeter provides multiple listeners to collect data. Flexible File Writer is a very useful plugin that allows users to write test results to a file in a custom format. This guide will detail how to install, configure, and use the Flexible File Writer plugin.

安装 Flexible File Writer 插件

使用 JMeter Plugins Manager 安装

安装 Flexible File Writer 插件:

  • 启动 JMeter,点击菜单栏中的 Options -> Plugins Manager。
  • 在插件管理器中搜索 Flexible File Writer,勾选并点击 Apply Changes and Restart JMeter。

配置 Flexible File Writer 插件

  1. To create a test plan:
  • Open JMeter and create a new Test Plan.
  1. To add a thread group:
  • 右键点击测试计划,选择 Add -> Threads (Users) -> Thread Group。
  • 配置线程组参数,例如线程数量(Number of Threads)、Ramp-Up 时间(Ramp-Up Period)和循环次数(Loop Count)。
  1. Add an HTTP request sampler:
  • 在线程组上右键点击,选择 Add -> Sampler -> HTTP Request。
  • Configure parameters related to HTTP requests, such as server name or IP, port number, path, and so on.
  1. 添加 Flexible File Writer 监听器:
  • 在线程组上右键点击,选择 Add -> Listener -> jp@gc - Flexible File Writer。

配置 Flexible File Writer 监听器

  1. Set the output file:
  • 在 Filename 字段中输入输出文件的路径和名称。 例如:/path/to/output/results.csv。
  1. Configuration File Format:
  • Format: Select a file format, usually CSV or Custom.
  • Custom String:如果选择 Custom 格式,可以在此字段中定义自定义的输出格式。 使用 ${变量名} 的形式来引用 JMeter 的变量。 例如:${timeStamp},${elapsed},${label},${responseCode},${responseMessage},${success},${failureMessage},${bytes},${sentBytes},${grpThreads},${allThreads},${URL},${Latency},${IdleTime},${Connect}。
  1. Select the fields you want to export:
  • 在 Variables 列表中选择需要输出的字段。 常见的字段包括 timeStamp、elapsed、label、responseCode、responseMessage、success 等。
  1. Other options:
  • Flush Interval: Sets the refresh interval in seconds. The default value is 0, which means that each sample record is written to the file immediately.
  • Add Timestamp to filename: If this option is checked, the output file name will contain a timestamp each time the test is run to avoid the file being overwritten.

Perform the test

  1. To save a test plan:
  • Select File -> Save As in the menu bar to save your test plan file (.jmx).
  1. Startup Test:
  • Click the green start button on the toolbar to start the test plan.
  1. View the output file:
  • Once the test is complete, review the configured output file to make sure the data has been properly documented.

Example configuration

Let's say we have a simple HTTP request test, configure the Flexible File Writer plugin as follows:

  • Filename:/path/to/output/results.csv
  • Format:Custom
  • Custom String:${timeStamp},${elapsed},${label},${responseCode},${responseMessage},${success},${bytes},${sentBytes},${grpThreads},${allThreads},${URL},${Latency},${IdleTime},${Connect}
  • Flush Interval:0

When configured in this way, the results are written to the results.csv file in the specified format each time the test is executed.

summary

The Flexible File Writer plugin provides JMeter users with flexible data logging capabilities, allowing users to customize the output format and content according to their needs. This is useful for results analysis and report generation. With this guide, you should be able to successfully install, configure, and use the Flexible File Writer plugin to record your test results.