Hudson Jmeter plugin example

under Construction

 Introduction

This recipe worked on Hudson/Ubuntu and is based on http://wiki.hudson-ci.org/display/HUDSON/JMeter Plugin

Potential Usages

  • Excercise Rest services
  • Generic Stress tests
  • Provisioning
  • More

ANT / Jmeter Installation

Install Jmeter on the same server as Hudson. If you have Java JDK 1.5 or 1.6 set up correctly and ant, you can achieve this just by  downloading a Jmeter package and expanding. In the /extra's directory is a jar library ant-jmeter-1.0.9.jar to allow you run jmeter from within Ant.

Make a Jmeter plan . For example, simple_get.jmx a jmeter plan (included as attachment), reads a series of hosts out of a CSV file and GET's them. The structure of the CSV file is host,URI,port, protocol (http/https) and looks similar to:

Hosts.txt
qa1-nl.sakaiproject.org,/portal/,80,http
qa1-nl.sakaiproject.org,/portal/,443,https

 To change location of the hosts.txt file, click on the "Lists of hosts file" icon.

If you run within Jmeter, expect a result similar to:



 

By adding more hosts and increasing the number of iterations in "Thread Group". You can get a page from any arbitrary web site.

The following Ant script will run the plan if it sits under the jmeter directory (/home/alan/Sakai/jakarta-jmeter-2.3.4) and then relative alans_examples//plans the results in alans_examples/results.
Note: Both the results and plans directory need to be read and writeable by the Hudson user.


 Ant script
<project>
    <property name="jmeter" location="/home/alan/Sakai/jakarta-jmeter-2.3.4" />
        <taskdef
        name="jmeter"
        classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"
        classpath="${jmeter}/extras/ant-jmeter-1.0.9.jar"   />
    <target name="jmeter.init">
        <echo message="[init] jmeter = ${jmeter}" />
        <mkdir  dir="alans_examples/results"/>
        <delete includeemptydirs="true">
            <fileset dir="alans_examples/results" includes="**/*" />
        </delete>
    </target>
    <target name="jmeter.tests" depends="jmeter.init" description="launch jmeter load tests">
        <echo message="[Running] jmeter tests..." />
        <jmeter
            jmeterhome="${jmeter}"
            resultlog="alans_examples/results/LoadTestResults.jtl">
            <testplans dir="alans_examples/plans" includes="*.jmx"/>
        </jmeter>
    </target>
</project>


Running Ant against the build.xml file should produce results similar to:

jmeter.init:
     [echo] [init] jmeter = /home/alan/Sakai/jakarta-jmeter-2.3.4

jmeter.tests:
     [echo] [Running] jmeter tests...
   [jmeter] Executing test plan: /home/alan/Sakai/jakarta-jmeter-2.3.4/alans_examples/plans/simple_get.jmx ==> /home/alan/Sakai/jakarta-jmeter-2.3.4/alans_examples/results/LoadTestResults.jtl
   [jmeter] log_file=jmeter.log java.io.FileNotFoundException: jmeter.log (Permission denied) <- Do not have permission as Hudson.
   [jmeter] [log_file-> System.out]
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.util.JMeterUtils: Setting Locale to en_US
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: Loading user properties from: /home/alan/Sakai/jakarta-jmeter-2.3.4/bin/user.properties
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: Loading system properties from: /home/alan/Sakai/jakarta-jmeter-2.3.4/bin/system.properties
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: Copyright (c) 1998-2009 The Apache Software Foundation
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: Version 2.3.4 r785646
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: java.version=1.6.0_16
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: java.vm.name=Java HotSpot(TM) 64-Bit Server VM
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: os.name=Linux
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: os.arch=amd64
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: os.version=2.6.31-16-generic
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: file.encoding=UTF-8
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: Default Locale=English (United States)
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: JMeter  Locale=English (United States)
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: JMeterHome=/home/alan/Sakai/jakarta-jmeter-2.3.4
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: user.dir  =/home/alan/Sakai/jakarta-jmeter-2.3.4/bin
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: PWD       =/home/alan/Sakai/jakarta-jmeter-2.3.4/bin
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: IP: 127.0.1.1 Name: alan-desktop FullName: alan-desktop
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.services.FileServer: Default base=/home/alan/Sakai/jakarta-jmeter-2.3.4/bin
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.services.FileServer: Set new base=/home/alan/Sakai/jakarta-jmeter-2.3.4/alans_examples/plans
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.JMeter: Loading file: /home/alan/Sakai/jakarta-jmeter-2.3.4/alans_examples/plans/simple_get.jmx
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.save.SaveService: Testplan (JMX) version: 2.2. Testlog (JTL) version: 2.2
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.save.SaveService: Using SaveService properties file encoding UTF-8
   [jmeter] 2009/12/07 15:40:10 INFO  - jmeter.save.SaveService: Using SaveService properties file version 697317
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.save.SaveService: Using SaveService properties version 2.1
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.save.SaveService: All converter versions present and correct
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.samplers.SampleResult: Note: Sample TimeStamps are START times
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.samplers.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Cannot find .className property for htmlParser, using default
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/html is
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for application/xhtml+xml is
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for application/xml is
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/xml is
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.sampler.HTTPSampler2: Local host = alan-desktop
   [jmeter] Created the tree successfully using /home/alan/Sakai/jakarta-jmeter-2.3.4/alans_examples/plans/simple_get.jmx
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.StandardJMeterEngine: Listeners will be started after enabling running version
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.StandardJMeterEngine: To revert to the earlier behaviour, define jmeterengine.startlistenerslater=false
   [jmeter] Starting the test @ Mon Dec 07 15:40:11 CET 2009 (1260196811195)
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.StandardJMeterEngine: Running the test!
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.util.CompoundVariable: Note: Function class names must contain the string: '.functions.'
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.util.CompoundVariable: Note: Function class names must not contain the string: '.gui.'
   [jmeter] Waiting for possible shutdown message on port 4445
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.JMeter: Running test (1260196811316)
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. Ramp up = 1.
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.threads.JMeterThread: jmeterthread.startearlier=true (see jmeter.properties)
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.threads.JMeterThread: Running PostProcessors in forward order
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.engine.StandardJMeterEngine: All threads have been started
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.services.FileServer: Stored: /home/alan/Desktop/hosts.txt
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.parser.HtmlParserHTMLParser: Using htmlparser version: 2.0 (Release Build Sep 17, 2006)
   [jmeter] 2009/12/07 15:40:11 INFO  - jmeter.protocol.http.parser.HTMLParser: Created org.apache.jmeter.protocol.http.parser.HtmlParserHTMLParser
   [jmeter] 2009/12/07 15:40:12 INFO  - jmeter.util.JsseSSLManager: Using default SSL protocol: TLS
   [jmeter] 2009/12/07 15:40:12 INFO  - jmeter.util.JsseSSLManager: SSL session context: per-thread
   [jmeter] 2009/12/07 15:40:12 INFO  - jmeter.util.SSLManager: JmeterKeyStore Location: /var/lib/hudson/.keystore
   [jmeter] 2009/12/07 15:40:12 INFO  - jmeter.util.SSLManager: KeyStore created OK, Type: JKS
   [jmeter] 2009/12/07 15:40:12 WARN  - jmeter.util.SSLManager: Keystore file not found, loading empty keystore
   [jmeter] 2009/12/07 15:40:14 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1
   [jmeter] 2009/12/07 15:40:14 INFO  - jmeter.engine.StandardJMeterEngine: Ending thread Thread Group 1-1
   [jmeter] 2009/12/07 15:40:14 INFO  - jmeter.engine.StandardJMeterEngine: Stopping test
   [jmeter] 2009/12/07 15:40:14 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
   [jmeter] 2009/12/07 15:40:14 INFO  - jmeter.services.FileServer: Close: /home/alan/Desktop/hosts.txt
   [jmeter] Tidying up ...    @ Mon Dec 07 15:40:14 CET 2009 (1260196814378)
   [jmeter] ... end of run
   [jmeter] 2009/12/07 15:40:14 INFO  - jmeter.engine.StandardJMeterEngine: Test has ended

BUILD SUCCESSFUL
Total time: 4 seconds
Recording JMeter reports /home/alan/Sakai/jakarta-jmeter-2.3.4/alans_examples/results/LoadTestResults.jtl
JMeter has reported a 0.0% of errors running the tests. Setting Build to SUCCESS
Finished: SUCCESS

Hudson Installation



 To run this from Hudson and create nicely formatted reports requires the addition of a Jmeter plugin.