| 
JMeter example source code file (listeners.xml)
 The JMeter listeners.xml source code
<?xml version="1.0"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<!DOCTYPE document
[
<!ENTITY sect-num '14'>
]>
<document prev="build-monitor-test-plan.html" next="remote-test.html" date="$Date: 2009-12-16 00:54:09 +0000 (Wed, 16 Dec 2009) $">
<properties>
  <title>User's Manual: Listeners
</properties>
<body>
<section name="§-num;. Introduction to listeners" anchor="intro">
<p>A listener is a component that shows the results of the
samples. The results can be shown in a tree, tables, graphs or simply written to a log
file. To view the contents of a response from any given sampler, add either of the Listeners "View
Results Tree" or "View Results in table" to a test plan. To view the response time graphically, add
graph results, spline results or distribution graph. 
The <complink name="listeners">Listeners 
section of the components page has full descriptions of all the listeners.</p>
<note>
Different listeners display the response information in different ways. 
However, they all write the same raw data to the output file - if one is specified.
</note>
<p>
The "Configure" button can be used to specify which fields to write to the file, and whether to 
write it as CSV or XML. 
CSV files are much smaller than XML files, so use CSV if you are generating lots of samples.
</p>
<p>
</p>
<p>
If you only wish to record certain samples, add the Listener as a child of the sampler.
Or you can use a Simple Controller to group a set of samplers, and add the Listener to that.
The same filename can be used by multiple samplers - but make sure they all use the same configuration!
</p>
</section>
<section name="§-num;.1 Default Configuration" anchor="defaults">
<p>
The default items to be saved can be defined in the jmeter.properties (or user.properties) file.
The properties are used as the initial settings for the Listener Config pop-up, and are also
used for the log file specified by the -l command-line flag (commonly used for non-GUI test runs).
</p>
<p>To change the default format, find the following line in jmeter.properties:
<p>jmeter.save.saveservice.output_format=
<p>
The information to be saved is configurable.  For maximum information, choose "xml" as the format and specify "Functional Test Mode" on the Test Plan element.  If this box is not checked, the default saved
data includes a time stamp (the number of milliseconds since midnight,
January 1, 1970 UTC), the data type, the thread name, the label, the
response time, message, and code, and a success indicator.  If checked, all information, including the full response data will be logged.</p>
<p>
The following example indicates how to set
properties to get a vertical bar ("|") delimited format that will
output results like:.</p>
<p>
<code>
<pre>
timeStamp|time|label|responseCode|threadName|dataType|success|failureMessage
02/06/03 08:21:42|1187|Home|200|Thread Group-1|text|true|
02/06/03 08:21:42|47|Login|200|Thread Group-1|text|false|Test Failed: 
	expected to contain: password etc.
</pre>
</code>
<p>
The corresponding jmeter.properties that need to be set are shown below.  One oddity
in this example is that the output_format is set to csv, which
typically
indicates comma-separated values.  However, the default_delimiter was
set to be a vertical bar instead of a comma, so the csv tag is a
misnomer in this case. (Think of CSV as meaning character separated values)</p>
<p>
<code>
<pre>
jmeter.save.saveservice.output_format=csv
jmeter.save.saveservice.assertion_results_failure_message=true
jmeter.save.saveservice.default_delimiter=|
</pre>
</code>
<p>
The full set of properties that affect result file output is shown below.
</p>
<code>
<pre>
#---------------------------------------------------------------------------
# Results file configuration
#---------------------------------------------------------------------------
# This section helps determine how result data will be saved.
# The commented out values are the defaults.
# legitimate values: xml, csv, db.  Only xml and csv are currently supported.
#jmeter.save.saveservice.output_format=xml
# true when field should be saved; false otherwise
# assertion_results_failure_message only affects CSV output
#jmeter.save.saveservice.assertion_results_failure_message=false
#
#jmeter.save.saveservice.data_type=true
#jmeter.save.saveservice.label=true
#jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
#jmeter.save.saveservice.response_data=false
# Save ResponseData for failed samples
#jmeter.save.saveservice.response_data.on_error=false
#jmeter.save.saveservice.response_message=true
#jmeter.save.saveservice.successful=true
#jmeter.save.saveservice.thread_name=true
#jmeter.save.saveservice.time=true
#jmeter.save.saveservice.subresults=true
#jmeter.save.saveservice.assertions=true
#jmeter.save.saveservice.latency=true
#jmeter.save.saveservice.samplerData=false
#jmeter.save.saveservice.responseHeaders=false
#jmeter.save.saveservice.requestHeaders=false
#jmeter.save.saveservice.encoding=false
#jmeter.save.saveservice.bytes=true
#jmeter.save.saveservice.url=false
#jmeter.save.saveservice.filename=false
#jmeter.save.saveservice.hostname=false
#jmeter.save.saveservice.thread_counts=false
#jmeter.save.saveservice.sample_count=false
#jmeter.save.saveservice.idle_time=false
# Timestamp format
# legitimate values: none, ms, or a format suitable for SimpleDateFormat
#jmeter.save.saveservice.timestamp_format=ms
#jmeter.save.saveservice.timestamp_format=MM/dd/yy HH:mm:ss
# Put the start time stamp in logs instead of the end
sampleresult.timestamp.start=true
# legitimate values: none, first, all
#jmeter.save.saveservice.assertion_results=none
# For use with Comma-separated value (CSV) files or other formats
# where the fields' values are separated by specified delimiters.
# Default:
#jmeter.save.saveservice.default_delimiter=,
# For TAB, since JMeter 2.3 one can use:
#jmeter.save.saveservice.default_delimiter=\t
#jmeter.save.saveservice.print_field_names=false
# Optional list of JMeter variable names whose values are to be saved in the result data files.
# Use commas to separate the names. For example:
#sample_variables=SESSION_ID,REFERENCE
# N.B. The current implementation saves the values in XML as attributes,
# so the names must be valid XML names.
# Versions of JMeter after 2.3.2 send the variable to all servers
# to ensure that the correct data is available at the client.
# Optional xml processing instruction for line 2 of the file:
#jmeter.save.saveservice.xml_pi=<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
</pre>
</code>
<p>
The date format to be used for the timestamp_format is described in <a
HREF="http://java.sun.com/j2se/1.5/docs/api/java/text/SimpleDateFormat.html">
<b>SimpleDateFormat.
Bear in mind that choosing a date format other than "ms" is likely to
make it impossible for JMeter to interpret the value when it is read
in later for viewing purposes.</p>
<subsection name="§-num;.1.1 Sample Variables" anchor="sample_variables">
<p>
Versions of JMeter after 2.3.1 allow one to use the <b>sample_variables 
property to define a list of additional JMeter variables which are to be saved with
each sample in the JTL files. The values are written to CSV files as additional columns,
and as additional attributes in XML files. See above for an example.
</p>
</subsection>
<subsection name="§-num;.1.2 Sample Result Save Configuration" anchor="sample_configuration">
<p>
Listeners can be configured to save different items to the result log files (JTL) by using the Config popup as shown below.
The defaults are defined as described in  the <a href="#defaults">Listener Default Configuration section above.
Items with (CSV) after the name only apply to the CSV format; items with (XML) only apply to XML format.
CSV format cannot currently be used to save any items that include line-breaks.
</p>
<figure image="sample_result_config.png"> | by | Bytes | <tr>de | Data encoding | <tr>dt | Data type | <tr>ec | Error count (0 or 1, unless multiple samples are aggregated) | <tr>hn | Hostname where the sample was generated | <tr>it | Idle Time = time not spent sampling (milliseconds) (generally 0) | <tr>lb | Label | <tr>lt | Latency = time to initial response (milliseconds) - not all samplers support this | <tr>na | Number of active threads for all thread groups | <tr>ng | Number of active threads in this group | <tr>rc | Response Code (e.g. 200) | <tr>rm | Response Message (e.g. OK) | <tr>s | Success flag (true/false) | <tr>sc | Sample count (1, unless multiple samples are aggregated) | <tr>t | Elapsed time (milliseconds) | <tr>tn | Thread Name | <tr>ts | timeStamp (milliseconds since midnight Jan 1, 1970 UTC) | <tr>varname | Value of the named variable (versions of JMeter after 2.3.1) | </table> <p> Versions 2.1 and 2.1.1 of JMeter saved the Response Code as "rs", but read it back expecting to find "rc". This has been corrected so that it is always saved as "rc"; either "rc" or "rs" can be read. </p> <note> Versions of JMeter after 2.3.1 allow additional variables to be saved with the test plan. Currently, the variables are saved as additional attributes. The testplan variable name is used as the attribute name. See <a href="#sample_variables">Sample variables (above) for more information. </note> </section> <section name="§-num;.8 Saving response data" anchor="saving"> <p> As shown above, the response data can be saved in the XML log file if required. However, this can make the file rather large, and the text has to be encoded so that it is still valid XML. Also, images cannot be included. <br/> Another solution is to use the Post-Processor <complink name="Save_Responses_to_a_file">Save Responses to a file. This generates a new file for each sample, and saves the file name with the sample. The file name can then be included in the sample log output. The data will be retrieved from the file if necessary when the sample log file is reloaded. </p> </section> <section name="§-num;.9 Loading (reading) response data" anchor="loading"> <p>To view an existing results file, you can use the File "Browse..." button to select a file. If necessary, just create a dummy testplan with the appropriate Listener in it. </p> <p>Results can be read from XML or CSV format files. When reading from CSV results files, the header (if present) is used to determine which fields were saved. <b>In order to interpret a header-less CSV file correctly, the appropriate JMeter properties must be set. </p> <note> Versions of JMeter up to 2.3.2 used to clear any current data before loading the new file. This is no longer done, thus allowing files to be merged. If the previous behaviour is required, use the menu item Run/Clear (Ctrl+Shift+E) or Run/Clear All (Ctrl+E) before loading the file. </note> </section> <section name="§-num;.10 Saving Listener GUI data" anchor="screencap"> <p>JMeter is capable of saving any listener as a PNG file. To do so, select the listener in the left panel. Click edit -> Save As Image. A file dialog will appear. Enter the desired name and save the listener. </p> <p> The Listeners which generate output as tables can also be saved using Copy/Paste. Select the desired cells in the table, and use the OS Copy short-cut (normally Control+C). The data will be saved to the clipboard, from where it can be pasted into another application, e.g. a spreadsheet or text editor. </p> <figure image="save_image.png">Figure 1 - Edit -> Save As Image </section> </body> </document>
| ... this post is sponsored by my books ... | |
         
           #1 New Release!  | 
      
         
           FP Best Seller  | 
  
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse 
URI on this website is
paid back to open source projects.