Jmeter Non GUI mode timestamp date format - jmeter

I am using JMeter in Non-GUI mode and able to generate the .csv and .jtl files but the timestamp in the results file is in Epoch format and I want it to be in date (yyyy/MM/dd HH:mm:ss) format.
I did go to the /bin/user.properties file and made the necessary changes, but still the report looks same as before and has the timestamp in epoch format. This is what my user.properties looks like
jmeter.save.saveservice.bytes = true
# Only available with HttpClient4
#jmeter.save.saveservice.sent_bytes=true
jmeter.save.saveservice.label = true
jmeter.save.saveservice.latency = true
jmeter.save.saveservice.response_code = true
jmeter.save.saveservice.response_message = true
jmeter.save.saveservice.successful = true
jmeter.save.saveservice.thread_counts = true
jmeter.save.saveservice.thread_name = true
jmeter.save.saveservice.time = true
jmeter.save.saveservice.connect_time = true
# the timestamp format must include the time and should include the date.
# For example the default, which is milliseconds since the epoch:
#jmeter.save.saveservice.timestamp_format = ms
# Or the following would also be suitable
jmeter.save.saveservice.timestamp_format = yyyy/MM/dd HH:mm:ss

Double check your user.properties file, maybe you have a duplicate property somewhere and JMeter picks the one it finds first. Another assumption: try removing starting (and ending, if any) whitespace, maybe the property cannot be parsed as a valid SimpleDateFormat pattern, check jmeter.log file for any suspicious entries
As a workaround you can override the timestamp format via -J command-line argument like:
jmeter -Jjmeter.save.saveservice.timestamp_format="yyyy/MM/dd HH:mm:ss" -n -t example.jmx -l example.csv
Demo:
More information on working with JMeter Properties: Apache JMeter Properties Customization Guide

Related

Convert epoch time format in jmeter

We are able to see a Timestamp column upon splitting the JTL file generated after a load test.
We want to convert the Timestamp (Which is currently in epoch format) to a more understandable and readable format such as dd/mm/yyyy hh:mm:ss.
Please help us.
Copy these properties from jmeter.properties file and add to user.properties file
#---------------------------------------------------------------------------
# Results file configuration
#---------------------------------------------------------------------------
# Timestamp format - this only affects CSV output files
# legitimate values: none, ms, or a format suitable for SimpleDateFormat
jmeter.save.saveservice.timestamp_format=ms
jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
just comment or uncomment the line jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS for getting epoch time or human readable timestamp format.
Need to restart the jmeter after updating the user.properties file

An Error message occurs on command prompt while generating Dashboard from Jmeter

I have started using JMeter 3.1 recently for load testing, all I wanted to do was generate a report dashboard from a csv file.
When I run the following command from Command Prompt:
jmeter -g (csv file location) -o (Destination folder to save HTML Dashboard)
I get the error shown below:
Could not parse timestamp<1.487+12> using format defined by property.saveservice.timestamp+format=ms on sample 1.487+12 .........
I have also attached the screenshot of the error message kindly refer below:
Below is my saveservice properties that I copied into user properties file:
jmeter.save.saveservice.bytes = true
jmeter.save.saveservice.label = true
jmeter.save.saveservice.latency = true
jmeter.save.saveservice.response_code = true
jmeter.save.saveservice.response_message = true
jmeter.save.saveservice.successful = true
jmeter.save.saveservice.thread_counts = true
jmeter.save.saveservice.thread_name = true
jmeter.save.saveservice.time = true
jmeter.save.saveservice.print_field_names=true
# the timestamp format must include the time and should include the date.
# For example the default, which is milliseconds since the epoch:
jmeter.save.saveservice.timestamp_format = ms
# Or the following would also be suitable
#jmeter.save.saveservice.timestamp_format = dd/MM/yyyy HH:mm
#save service assertion
jmeter.save.saveservice.assertion_results_failure_message = true
I am not able to figure out the resaon, any help in this regard will be much appreciated.
please help, also please let me know if any addition information is required.
I have followed the below link to generate Dashboard:
http://jmeter.apache.org/usermanual/generating-dashboard.html
The answer is in your question itself:
Could not parse timestamp<1.487+12>
According to your configuration, JMeter expects first column to be in Unix timestamp format like 1487047932355 (time since beginning of Unix epoch in milliseconds)
Another supported format is yyyy/MM/dd HH:mm:ss.SSS like 2017/02/14 05:52:12.355
So there are several constraints:
The value of jmeter.save.saveservice.timestamp_format = ms should be the same during test execution and dashboard generation
You need to restart JMeter to pick the properties up. For example if you ran the test, then amended properties and then tried to generate dashboard - it might fail
There are no duplicate properties
You don't do anything with the .jtl results file between test execution and dashboard generation
My expectation is that you opened .jtl results file with MS Excel which converted timestamps into scientific notation and saved so most probably you will be able to do the opposite.
Just in case I would also recommend getting familiarised with Apache JMeter Properties Customization Guide
The default timestamp format in JMeter csv and logs is given in a Unix style format , but you can change it .
Go to (jmeterDirectory)/bin .
open jmeter.properties file .
Search for the following :-
jmeter.save.saveservice.timestamp_format
You will find it commented (Start with #) . Uncomment it and restart the Jmeter .
You can update this above property with the format you need

How to calculate elapsed time between two HTTP samplers in JMeter

I tried to calculate elapsed time as follows. I added the code in Beanshell Post Processor something like this (with courtesy of another thread in StackOverflow).
For the sampler1
long request1 = prev.getTime();
vars.put("sampler1", String.valueOf(request1));
And in sampler 2 I added .
long request2 = prev.getTime();
vars.put("sampler2", String.valueOf(request2));
long request1 = Long.parseLong(vars.get("sampler1"));
long request2 = Long.parseLong(vars.get("sampler2"));
long delta = (request1 - request2); // calculate difference
log.info("Time difference is: " + delta + " ms");
And the same delta is captured in .csv file as follows.
FileOutputStream out = new FileOutputStream("delta.csv", true);
out.write((String.valueOf(delta)).getBytes("UTF-8"));
out.write(System.getProperty("line.separator").getBytes("UTF-8"));
out.flush();
out.close();
I do get the values in the CSV file in a single row.
But I'm looking for a way to capture these values using sample variables and map it to other sample variables that I'm capturing in another CSV file.
I appreciate if someone can provide a way to do this.
Instead of writing variable to another CSV file using Beanshell go for Sampler Variables property instead.
Add the next line to the end of 2nd PostProcessor:
vars.put("delta", String.valueOf(delta));
Add the following line to user.properties file (lives in JMeter's "bin" folder)
sample_variables=delta
On next JMeter restart you will see a new column having "delta" variable value in .jtl results file.
Another approach of setting Sample Variables property is passing it via -J command line argument as:
jmeter -Jsample_variables=delta,somethingelse -n -t testplan.jmx -l results.jtl
See Apache JMeter Properties Customization Guide for more information using, setting and overriding this and other JMeter properties.
You can also use Flexible File Writer for that (you will still need Sample Variables).

Jmeter beanshell script - Polish first and last name

i have a little problem with my jmeter test plan.
i have a jdbc request to extract customers in sql databases
from this sql query i retrieve first name and last name only
after that i have a beanshell little script to write all my customers in a csv file :
f = new FileOutputStream(vars.get("InputFilePath"));
p = new PrintStream(f);
nb_customer=Integer.parseInt(vars.get("NOM_#"));
for (i=1;i<=nb_customer;i++) {
p.println(vars.get("NOM_"+i) + ";" + vars.get("PRENOM_"+i));
}
p.close();
f.close();
my problem is that it is an application for our subsidiary company in polska
so, all customers first and last name are in polish language with different symbol, characters.
in the csv file, they appears with a ? in spite of the real character.
can you help me please ?
thanks a lot
Ludo
Try explicitly setting encoding to UTF-8, initialize PrintStream as:
p = new PrintStream(f, true, "UTF-8");
Check out JMeter default encoding as:
log.info(System.getProperty("file.encoding"));
If output is different from UTF-8 add the next line to system.properties file (lives under /bin folder of your JMeter installation:
file.encoding=UTF-8
and restart JMeter. Alternatively you can pass it via -D command line argument like:
jmeter -Dfile.encoding=UTF-8
See Apache JMeter Properties Customization Guide for more information on Jmeter properties and ways of setting and overriding them.
Check file contents in JMeter itself by using FileUtils.readFileToString() method like:

How to update a program with a daily changing file name?

I have a program that reads in a file and does some parsing to it. The file is generated by another program every night. Due to the ICD the date is part of the file name.
The file name changes every night due to the date change so I am not sure how to have my program change the fileIn name to accommodate this.
If the current fileIn is:
in20120103out.dat
Tomorrow's fileIn is:
in20120104out.dat
filename = Time.now.strftime("in%Y%m%dout.dat")
or
require 'date'
filename = Date.today.strftime("in%Y%m%dout.dat")
strftime means string format for time. The %-parameters are placeholder for Year (Y), month (m), day (d). (There are more placeholders, e.g. year without century...)
You can use the strftime() method to generate the date portion of the filename:
t = Time.­now
filename = "in#{t.strftime('%Y%m%d')}out.dat"
And then use the filename variable to open the file as normal.

Resources