Search in sources :

Example 1 with SampleSaveConfiguration

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();
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) AssertionResult(org.apache.jmeter.assertions.AssertionResult) StatisticalSampleResult(org.apache.jmeter.samplers.StatisticalSampleResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Date(java.util.Date)

Example 2 with SampleSaveConfiguration

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());
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) File(java.io.File)

Example 3 with SampleSaveConfiguration

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());
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) File(java.io.File)

Example 4 with SampleSaveConfiguration

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);
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) CorrectedResultCollector(kg.apc.jmeter.vizualizers.CorrectedResultCollector)

Example 5 with SampleSaveConfiguration

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());
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) File(java.io.File)

Aggregations

SampleSaveConfiguration (org.apache.jmeter.samplers.SampleSaveConfiguration)19 SampleResult (org.apache.jmeter.samplers.SampleResult)7 File (java.io.File)4 IOException (java.io.IOException)3 SampleEvent (org.apache.jmeter.samplers.SampleEvent)3 StatisticalSampleResult (org.apache.jmeter.samplers.StatisticalSampleResult)3 FileNotFoundException (java.io.FileNotFoundException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Date (java.util.Date)1 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)1 AssertionResult (org.apache.jmeter.assertions.AssertionResult)1 LoopController (org.apache.jmeter.control.LoopController)1 StandardJMeterEngine (org.apache.jmeter.engine.StandardJMeterEngine)1 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)1