Our legacy site: www.webwob.com   

VUgen scripting methods (page 3)

This page will cover more BASH scripting methods, following on from the legacy site pages.

     LoadRunner CI/CD      *_LR_CI_*      LR_CI_+      Email_out      Email_in      Cookies 1      TUTORIAL      sprintf      debug      VUgen      Kill -9      disk space      AWS S3      dig (DNS++)      substitute      curl with timings      LR_Jenkins_graphs     

    

Areas covered on this page

1. Quick LoadRunner results to graphs

2. Output results to HTML page as well


Run a quick LR script in standalone mode and graph the results by checking the output log


Step 1. Windows batch (code given as text below):

Windows batch

  "C:\loadrunner\program\HP\loadrunner\bin\mmdrv.exe" -usr "Z:\github\PerformanceTesting\scripts\mint\mint_test_script1\mint_test_script1.usr"
  
  cp "Z:\github\PerformanceTesting\scripts\mint\mint_test_script1\output.txt" .
  
  
Step 2. Shell script (code given as text below):

Shell script
  
  grep -o "PASS: user login:" output.txt
  
  grep -o "PASS: user login:" output.txt | wc -l
  
  result=$(grep -o "PASS: user login:" output.txt | wc -l)
  echo "result = ${result}"
  
  if [ "$result" != "5" ]
  then
      echo TERMS test FAILED
  else
      echo TERMS test PASSED
  fi
  
  rm -f *.jtl
  
  #EXAMPLE JTL FILE:
  #<?xml version="1.0" encoding="UTF-8"?>
  #<testResults version="1.2">
  #<httpSample t="7789" ts="1495203777317" s="true" lb="eventTime" rc="200"/>
  #</testResults>
  
  now=$(date +%s)
  now=$(($now * 1000))
  
  echo '<?xml version="1.0" encoding="UTF-8"?>' > count.jtl
  echo '<testResults version="1.2">' >> count.jtl
  echo -n '<httpSample t="' >> count.jtl
  echo -n "${result}" >> count.jtl
  echo -n '" ts="' >> count.jtl
  echo -n ${now} >> count.jtl
    
Note: on the next line you might want to adjust the pass/fail in the jtl file, depending on the results

  echo '" s="true" lb="eventTime" rc="200"/>' >> count.jtl
  echo '</testResults>' >> count.jtl
  
  
Step 3. Groovy Post Build (code given as text below - Don't need the first line!):

Shell script

  if(manager.logContains(".*TERMS test PASSED.*"))
  {
      manager.listener.logger.println("Groovy setting build to PASSED")
      manager.build.@result = hudson.model.Result.SUCCESS
  }
  else
  {
      manager.listener.logger.println("Groovy setting build to FAILED")
      manager.build.@result = hudson.model.Result.FAILURE
  }
  
Step 4. Trend Graphs (code given as text below):

Trend graphs

  **/*.jtl
  5
  10
  
Results: (Quick example):

Resultant graphs

Last run failed (because the last count was 4 rather than the expected 5):

Resultant graphs


Output results to HTML page

This is taken from my standard CI BASH scripts

  
  > email: One more thing worth highlighting. I had to produce trend results for users without the Jenkins graphs – sometimes we don’t use them, especially if this is run through Bamboo – so I have built html reports as well. BUT, I made them a bit tricky to find! They are under here – follow this email trail:
  
  
Results: (Quick example):

Resultant graphs

Scroll down, they are named: rep85.html, rep90.html and rep95sla.html:
Resultant graphs

If you click on one of these, you’ll see the trend numbers for that percentile (note, this Jenkins job has unfortunately been run with several differnt scenarios in there over time):
Resultant graphs

CODE for the above

  
#Build the temp_r variable for colouring certain cells:

  temp_r=$((1 + RANDOM % 10))
  
  
  
#Start the HTML file OR remove the bottom of the table if it's already there:

  if [ ! -f rep90.html ]; then
      echo "rep90.html File not found. Start it."
      echo '<html><head><title>Percentiles 90</title></head><body><table border="1" style="border-collapse: collapse;">' > rep90.html
  else
      echo "rep90.html file found"
      sed --in-place "\#</table></body></html>#d" rep90.html
  fi
  
  
  
#Enter the version name for this set of results. A proper version can be given by setting ${version} before calling this script. OR the most recent results directory will be used, which does have a date on it:
  
  ls usage notes:
  -d, --directory
               list directories themselves, not their contents
  -t     sort by modification time, newest first
  -r, --reverse
               reverse order while sorting
(don't need this here in fact)
  
  ls -dt res*
  res_f=$(ls -dt res* | head -1)
  
  if [ "$temp_r" -le "3" ]
  then
      echo -n "<tr><td bgcolor="#ffffcc">${res_f}</td>" >> rep90.html
      echo -n "<td bgcolor="#ffffcc">${version}</td>" >> rep90.html
  else
      echo -n "<tr><td>${res_f}</td>" >> rep90.html
      echo -n "<td>${version}</td>" >> rep90.html
  fi
  
  
  
  
loop over all the metrics themselves, colouring some of them:

  
  if [ "$temp_r" -le "3" ]
      then
          echo -n "<td>${our_metric}</td><td bgcolor="#ffffcc">${jtl_time}</td>" >> rep90.html
      else
          echo -n "<td>${our_metric}</td><td>${jtl_time}</td>" >> rep90.html
  fi
          
  
finish the file:

          
  echo '</tr>' >> rep90.html
  echo '</table></body></html>' >> rep90.html