簡體   English   中英

如何使用 JMeter 報告生成器生成 JSON 文件

[英]How to generate a JSON file using JMeter Report Generator

我正在嘗試使用 ReportGenerator 創建一個帶有 JMeter 的 statistics.json 文件,其中填充了 my.jmx 測試的結果。 用 JMeter 可以做到這一點嗎?

I have gone through this tutorial: https://jmeter.apache.org/usermanual/generating-dashboard.html which focuses on creating an html dashboard using the Report Generator, but I have a project requirement of creating/updating a statstics.json文件也是如此。 我已經使用 JSON 提取器后處理器提取了必要的數據,我可以從該提取器獲取自定義變量以顯示在我的調試響應和 CSV 文件中(在將一些 sample_variables 添加到 user.properties 之后)。 不幸的是,我未能找到有關如何使用這些響應創建 JSON 文件的更多信息。

在我的 reportgenerator.properties 文件中,我看到的與 json 相關的唯一部分是:

jmeter.reportgenerator.exporter.json.classname=org.apache.jmeter.report.dashboard.JsonExporter
jmeter.reportgenerator.exporter.json.property.output_dir=report-output

我正在尋找一些允許我編輯 JSON 文件中的內容的設置,但我在文檔中查找信息時遇到了麻煩。 我是否需要在另一個設置文件中發送或設置我的自定義變量? 任何幫助澄清這一點將不勝感激!

查看JMeter 源代碼,您無法有效地控制要導出到統計信息中的內容。json 外部文件,您將不得不修改 JsonExporter ZA2F2ED4F8EBC2CBB4C21A29DC2CBB4C21A29DC40AB61DZ 代碼的存儲位置以及如何存儲自己的AbstractDataExporter代碼。

private void createStatistic(Map<String, SamplingStatistic> statistics, MapResultData resultData) {
    LOGGER.debug("Creating statistics for result data:{}", resultData);
    SamplingStatistic statistic = new SamplingStatistic();
    ListResultData listResultData = (ListResultData) resultData.getResult("data");
    statistic.setTransaction((String) ((ValueResultData)listResultData.get(0)).getValue());
    statistic.setSampleCount((Long) ((ValueResultData)listResultData.get(1)).getValue());
    statistic.setErrorCount((Long) ((ValueResultData)listResultData.get(2)).getValue());
    statistic.setErrorPct(((Double) ((ValueResultData)listResultData.get(3)).getValue()).floatValue());
    statistic.setMeanResTime((Double) ((ValueResultData)listResultData.get(4)).getValue());
    statistic.setMinResTime((Long) ((ValueResultData)listResultData.get(5)).getValue());
    statistic.setMaxResTime((Long) ((ValueResultData)listResultData.get(6)).getValue());
    statistic.setMedianResTime((Double) ((ValueResultData)listResultData.get(7)).getValue());
    statistic.setPct1ResTime((Double) ((ValueResultData)listResultData.get(8)).getValue());
    statistic.setPct2ResTime((Double) ((ValueResultData)listResultData.get(9)).getValue());
    statistic.setPct3ResTime((Double) ((ValueResultData)listResultData.get(10)).getValue());
    statistic.setThroughput((Double) ((ValueResultData)listResultData.get(11)).getValue());
    statistic.setReceivedKBytesPerSec((Double) ((ValueResultData)listResultData.get(12)).getValue());
    statistic.setSentKBytesPerSec((Double) ((ValueResultData)listResultData.get(13)).getValue());
    statistics.put(statistic.getTransaction(), statistic);
}

一個更簡單的選擇是使用靈活文件編寫器將示例變量寫入單獨的文件

我將留下已接受的答案,因為它是正確的。 但是,我想補充一點,我能夠通過使用 JSR223 后處理器編寫 groovy 腳本來完成我的要求,該腳本在我需要的任何地方創建一個 csv 文件,並用我需要的任何數據填充它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM