I am trying to create a statistics.json file with JMeter using ReportGenerator, populated with the results of my .jmx tests. Is it possible to do this with 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 file as well. I have already pulled the necessary data using a JSON Extractor post processor, and I can get the custom variables from that extractor to show up in my debug response, and in my CSV file (after adding some sample_variables to user.properties). Unfortunately I have been unsuccessful in finding more info about how to create a JSON file with these responses.
In my reportgenerator.properties file, the only parts I see that relate to json are:
jmeter.reportgenerator.exporter.json.classname=org.apache.jmeter.report.dashboard.JsonExporter
jmeter.reportgenerator.exporter.json.property.output_dir=report-output
I'm looking for some settings that would allow me to edit what goes into that JSON file, but I'm having trouble finding information in the docs. Do I need to be sending or setting my custom variables in another settings file? Any help clarifying this would be much appreciated!
Looking at JMeter source code you cannot efficiently control what's being exported into statistics.json file externally, you will have to either amend the JsonExporter class code or come up with your own implementation of the AbstractDataExporter and choose what, where and how to store.
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);
}
An easier option would be writing your sample variables into a separate file using Flexible File Writer