use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter by apache.
the class CSVSaveService method resultToDelimitedString.
/**
* Convert a result into a string, where the fields of the result are
* separated by a specified String.
*
* @param event
* the sample event to be converted
* @param delimiter
* the separation string
* @return the separated value representation of the result
*/
public static String resultToDelimitedString(SampleEvent event, final String delimiter) {
StringQuoter text = new StringQuoter(delimiter.charAt(0));
SampleResult sample = event.getResult();
SampleSaveConfiguration saveConfig = sample.getSaveConfig();
if (saveConfig.saveTimestamp()) {
if (saveConfig.printMilliseconds()) {
text.append(sample.getTimeStamp());
} else if (saveConfig.threadSafeLenientFormatter() != null) {
String stamp = saveConfig.threadSafeLenientFormatter().format(new Date(sample.getTimeStamp()));
text.append(stamp);
}
}
if (saveConfig.saveTime()) {
text.append(sample.getTime());
}
if (saveConfig.saveLabel()) {
text.append(sample.getSampleLabel());
}
if (saveConfig.saveCode()) {
text.append(sample.getResponseCode());
}
if (saveConfig.saveMessage()) {
text.append(sample.getResponseMessage());
}
if (saveConfig.saveThreadName()) {
text.append(sample.getThreadName());
}
if (saveConfig.saveDataType()) {
text.append(sample.getDataType());
}
if (saveConfig.saveSuccess()) {
text.append(sample.isSuccessful());
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
String message = null;
AssertionResult[] results = sample.getAssertionResults();
if (results != null) {
// Find the first non-null message
for (AssertionResult result : results) {
message = result.getFailureMessage();
if (message != null) {
break;
}
}
}
if (message != null) {
text.append(message);
} else {
// Need to append something so delimiter is
text.append("");
// added
}
}
if (saveConfig.saveBytes()) {
text.append(sample.getBytesAsLong());
}
if (saveConfig.saveSentBytes()) {
text.append(sample.getSentBytes());
}
if (saveConfig.saveThreadCounts()) {
text.append(sample.getGroupThreads());
text.append(sample.getAllThreads());
}
if (saveConfig.saveUrl()) {
text.append(sample.getURL());
}
if (saveConfig.saveFileName()) {
text.append(sample.getResultFileName());
}
if (saveConfig.saveLatency()) {
text.append(sample.getLatency());
}
if (saveConfig.saveEncoding()) {
text.append(sample.getDataEncodingWithDefault());
}
if (saveConfig.saveSampleCount()) {
// Need both sample and error count to be any use
text.append(sample.getSampleCount());
text.append(sample.getErrorCount());
}
if (saveConfig.saveHostname()) {
text.append(event.getHostname());
}
if (saveConfig.saveIdleTime()) {
text.append(event.getResult().getIdleTime());
}
if (saveConfig.saveConnectTime()) {
text.append(sample.getConnectTime());
}
for (int i = 0; i < SampleEvent.getVarCount(); i++) {
text.append(event.getVarValue(i));
}
return text.toString();
}
use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter-plugins by undera.
the class JMXMonCollector method setupSaving.
private void setupSaving(String fileName) {
SampleSaveConfiguration config = getSaveConfig();
JMeterPluginsUtils.doBestCSVSetup(config);
setSaveConfig(config);
setFilename(fileName);
log.info("JMXMon metrics will be stored in " + new File(fileName).getAbsolutePath());
}
use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter-plugins by undera.
the class MonitoringResultsCollector method setupSaving.
private void setupSaving(String fileName) {
SampleSaveConfiguration config = getSaveConfig();
JMeterPluginsUtils.doBestCSVSetup(config);
setSaveConfig(config);
setFilename(fileName);
log.info(getPrefix() + " monitoring metrics will be stored in " + new File(fileName).getAbsolutePath());
}
use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter-plugins by undera.
the class FilterResultsTool method processParams.
@Override
protected int processParams(ListIterator args) throws UnsupportedOperationException, IllegalArgumentException {
String outputFile = "out.res";
LoggingManager.setPriority(Priority.INFO);
// first process params without worker created
while (args.hasNext()) {
String nextArg = (String) args.next();
if (nextArg.equals("--loglevel")) {
args.remove();
String loglevelStr = (String) args.next();
args.remove();
LoggingManager.setPriority(loglevelStr);
}
}
// rewind it
while (args.hasPrevious()) {
args.previous();
}
CorrectedResultCollector collector = filterResults.getCollector();
SampleSaveConfiguration saveConfig = collector.getSaveConfig();
while (args.hasNext()) {
String nextArg = (String) args.next();
log.debug("Arg: " + nextArg);
if (nextArg.equalsIgnoreCase("--input-file")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing input file JTL (or CSV) file name");
}
collector.setProperty("filename", (String) args.next());
log.info("--input-file " + collector.getFilename());
} else if (nextArg.equalsIgnoreCase("--output-file")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing Output file name");
}
// outputfile is a parameter to FilterResults
outputFile = (String) args.next();
log.info("--output-file " + outputFile);
} else if (nextArg.equalsIgnoreCase("--include-labels")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing include labels list");
}
collector.setIncludeLabels((String) args.next());
log.info("--include-labels " + collector.getList(CorrectedResultCollector.INCLUDE_SAMPLE_LABELS));
} else if (nextArg.equalsIgnoreCase("--exclude-labels")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing exclude labels list");
}
collector.setExcludeLabels((String) args.next());
log.info("--exclude-labels " + collector.getList(CorrectedResultCollector.EXCLUDE_SAMPLE_LABELS));
} else if (nextArg.equalsIgnoreCase("--success-filter")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing success filter flag (true/false)");
}
collector.setSuccessOnlyLogging(Boolean.valueOf((String) args.next()));
log.info("--success-filter " + collector.isSuccessOnlyLogging());
} else if (nextArg.equalsIgnoreCase("--include-label-regex")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing include label regex flag (true/false)");
}
collector.setEnabledIncludeRegex(Boolean.valueOf((String) args.next()));
log.info("--include-label-regex " + collector.getRegexChkboxState(CorrectedResultCollector.INCLUDE_REGEX_CHECKBOX_STATE));
} else if (nextArg.equalsIgnoreCase("--exclude-label-regex")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing exclude label regex flag (true/false)");
}
collector.setEnabledExcludeRegex(Boolean.valueOf((String) args.next()));
log.info("--exclude-label-regex " + collector.getRegexChkboxState(CorrectedResultCollector.EXCLUDE_REGEX_CHECKBOX_STATE));
} else if (nextArg.equalsIgnoreCase("--start-offset")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing start offset flag (sec)");
}
collector.setStartOffset((String) args.next());
log.info("--start-offset " + collector.getPropertyAsString(CorrectedResultCollector.START_OFFSET));
} else if (nextArg.equalsIgnoreCase("--end-offset")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing end offset flag (sec)");
}
collector.setEndOffset((String) args.next());
log.info("--end-offset " + collector.getPropertyAsString(CorrectedResultCollector.END_OFFSET));
} else if (nextArg.equalsIgnoreCase("--save-as-xml")) {
if (!args.hasNext()) {
throw new IllegalArgumentException("Missing save as xml flag (true/false, true = XML/false = CSV)");
}
saveConfig.setAsXml(Boolean.valueOf((String) args.next()));
log.info("--save-as-xml " + saveConfig.saveAsXml());
} else {
throw new UnsupportedOperationException("Unrecognized option: " + nextArg);
}
}
collector.setSaveConfig(saveConfig);
return doJob(collector, outputFile);
}
use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter-plugins by undera.
the class PerfMonCollector method setupSaving.
private void setupSaving(String fileName) {
SampleSaveConfiguration config = getSaveConfig();
JMeterPluginsUtils.doBestCSVSetup(config);
setSaveConfig(config);
setFilename(fileName);
log.info("PerfMon metrics will be stored in " + new File(fileName).getAbsolutePath());
}
Aggregations