JM bespoke

JMeter bespoke request calling module

see below for updates: Download project

Put these extensions under jmeter/lib/ext: jmeter

Before downloading, please read our terms and conditions

NOTE: This project has been developed over several years in my spare time and whilst working for several different clients. This is open source and has no commercial ties to any company I have worked for. Screen shots may reflect this as they are home made and may not be truly representative of a full commercial environment. However, these solutions have been used commercially and are known to work in those environments.

Ultimately I want to run tests straight from raw log files from our app servers. This is the first step and it shouldn't take much effort to add specific metrics etc. I'll discuss that below.

So, this script is written in a JSR223 request sampler, set to use the groovy language. It loads urls from a csv file. URLs are full, such as:

The script uses some java (off the internet) to call the URL and then sets various JMeter response values. I also added some header setting lines. You don't have complete control on all headers with this method but it has been ok for me so far. I then also grabbed the response headers (again cobbled together the code off the internet).

The Script

    import java.util.List;
    import java.util.Map;

    String url = vars.get('url1');
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    // optional default is GET
    //add request header
    con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0");

    con.setRequestProperty("Accept-Encoding", "gzip, deflate");
    con.setRequestProperty("Accept-Language", "en-GB,en;q=0.5");

    int responseCode = con.getResponseCode();
    //System.out.println("\nSending 'GET' request to URL : " + url);
    //System.out.println("Response Code : " + responseCode);
    BufferedReader input = new BufferedReader(
           new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();
    while ((inputLine = input.readLine()) != null) {
    //print result

    StringBuffer myHeaders = new StringBuffer();
    Map<String, List<String>> map = con.getHeaderFields();
     //System.out.println("Printing Response Header...\n");
    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
    //System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());

    //trim off the square brackets
             length = String.valueOf(entry.getValue()).length()
             if(!entry.getKey())//first one is null and gives response code
             myHeaders.append(String.valueOf(entry.getValue()).substring(1,length-1) + '\n')
           myHeaders.append(entry.getKey() + ': ' + String.valueOf(entry.getValue()).substring(1,length-1) + '\n')



Name the JSR223 Request Sampler

The name of the sampler matters. If you want to do an aggregate report on these calls, looking at TPS and average response times etc. give the sampler a fixed name such as 'my_url'. But if you want timing for each request logged into a file (an assertions file in my case), then you can name the sampler with a variable such as ${url1} where 'url1' is setup in the csv file reader. (I'll attach the script).

Assertion on results

In this general script I am just asserting on a 200 but you might like to add 302, 304 etc. Also, at work I would add assertion on not seeing '[Ee]rror.css' as that would be on our main error pages.

But the main thing about the assertions are you can get separate csv files for the results and this leads into my next steps section below:

Next steps

I want to add specific timing for various groups of calls. My plan is to grep the url and look for terms such as '/brands/' or '/categories/'. I will then name the request sampler based on this AND name the assertions, and the assertions csv file, based on the same variable. This should then give me graphs and timings for groups of calls. And this could then all be automatic, based off the latest raw log file. I'll update this page as I progress through this idea.

Latest updates

I've done a bit more work on this script, with all the metrics and few more details in the JSR223 sampler, so you may want to pick up the latest version from here.

[Home] [About (CV)] [Contact Us] [JMeter Cloud] [webPageTest] [_64 images] [asset moniitor] [Linux Monitor] [Splunk ETL] [Splunk API] [AWS bash] [LR Rules OK] [LR Slave] [LR CI Graphs] [LoadRunner CI] [LR CI Variables] [LR Bamboo] [LR Methods] [LR CI BASH] [Bash methods] [Jenkins V2] [Streaming vid] [How fast] [Finding Issues] [Reporting] [Hand over] [VB Scripts] [JMeter tips] [JM bespoke] [JMeter RAW] [Dynatrace] [Documents] [FAQ] [Legal]

In the Cartesian Elements Ltd group of companies