JMeter - print out jdbc connection details - jmeter

I'm trying to test the loadbalancing on MySQL cluster and send some requests with JMeter.
The JDBC Database URL is set like this: jdbc:mysql:loadbalance://ip1,ip2/ndbinfo?loadBalanceBlacklistTimeout=5000
My intention is to print each request sent to DB to include the ip1 or ip2, to check load balancing capabilities.
I've tried to include JSR223 Sampler and java code
import java.sql.Connection;
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
Connection conn = DataSourceElement.getConnection("jdbcConfig");
System.out.println("conn: "+conn);
This doesn't work as planned. I've found a post to use JSR223 with groovy (never used it before) and this code. But for some reasons I am unable to select groovy language in the sampler.
Any help would be appreciated.

I'm not too sure whether you will be able to distinguish ip1 or ip2 incormation, however.
If you want to continue using Groovy you need groovy-all.jar in JMeter classpath.
You can consider switching to Beanshell, it doesn't require any additional jars as it's built-in.
Your System.out.println("conn: "+conn); stanza result won't help as it'll return something like com.mysql.jdbc.JDBC4Connection#7ada3b58. I would suggest to amend last line to look as follows:
log.info(conn.getMetaData().getURL());
So the output could go to 'jmeter.log' file and it would be something meaningful. However I expect that it will be that connection string from JDBC Connection Configuration. If not - than we're done.
And finally, I would suggest obtaining current instance IP directly on the MySQL instance via something like:
select host from information_schema.processlist;
in JDBC Request sampler. You can print it using Beanshell pre-processor to STDOUT or to log if necessary.
See How to use Beanshell guide for more details on extending JMeter with Beanshell scripting.

Related

JMeter Beanshell Sampler - Not setting properties values

I am using a JMeter Beanshell Sampler to preload a properties file:
'''FileInputStream is = new FileInputStream(new File("${PROPERTIES_FILE}"));
props.load(is);
is.close();'''
However, on the first run some of the values are not set? When I run again it sets all the values.
JMeter First Run - Response code:
'''Response message:javax.jms.JMSException: Could not connect to broker URL:tcp://:61616?keepAlive=true.'''
The IP Address was not set within the properties file.
Any help would be appreciated
I think JMS test elements are being initialized before any Sampler is executed (including the Beanshell Sampler)
So I would recommend:
Removing your Beanshell Sampler completely
Passing the .properties file via -q command-line argument like:
jmeter -q /path/to/your/file.properties -t testplan.jmx ....
Also be informed that according to JMeter Best Practices you should be using JSR223 Test Elements and Groovy language for scripting so going forward consider using Groovy, more information: Apache Groovy - Why and How You Should Use It

JMeter Beanshell listner script sometimes get ignore in non-GUI mode

I created JMeter Test and under first "HTTP Request" I created a Beanshell listner script which works fine when using GUI but 8 out of 10 times the script totally get ignored in non-GUI mode.
I am also running these test in Gitlab CI using Docker Image "justb4/jmeter:latest" and Beanshell script also get ignored there. I don't know whats wrong there it is working fine with GUI
There is no such thing as "get ignored" in JMeter world, it either passes or fails, in case of failure you should see the relevant message(s) in the jmeter.log file
Also be aware that you should not be using Beanshell at all, starting from JMeter 3.1 you should be using JSR223 Listener and Groovy language for scripting, one of Beanshell's disadvantages is that it's being interpreted each time while Groovy scripts can be compiled and cached providing the most optimal performance. See Apache Groovy - Why and How You Should Use It article for more details.
Also be informed that we cannot efficiently help without seeing your code and the aforementioned jmeter.log file.

Can't get property value in Jmeter master-slave mode

I wrote a jmeter plugin which is used to analyze jmeter sample event, and send the results to a specified server. In this plugin, user can config the server IP/Port etc. These configurations normally use the variable and read them from given CSV file(using CSV config plugin). For example, the variables could be filled like: ${serverIP}, ${serverPort} on plugin GUI.
Ok, my jmx and plugin with these configurations can work well in single mode. But now, I have requirement to run them in Master-Slave mode, the problem is coming, the ${serverIP}, ${serverPort} can't not be converted to real value in Master side. I added some logs in my plugin codes which I used Jemter API to read its value
public String getServerIP() {
return getPropertyAsString(SERVER_IP);
}
and found jmeter straightly return me with the variable name: ${serverIP}, not like what it did in single mode that convert them to real value.
I googled and searched Jmeter doc, but nothing found, How could I let jmeter read configured variable from given CSV file in Master side(I know it could do this in Slave side). Can't Jmeter support it?
Any help are really appreciated! If you need more infos, please let me know, Thanks a lot!

What steps are included when Jmeter measuring JDBC response time

I am using Jmeter to send JDBC requests to a database.
I was wondering what steps are included when measuring response time.
For example, I am sending a select request to database.
I was the first query response time is larger than ours and I am assuming the first requests require establishing connection to the database and the rest requests are using connection pooling.
I want to know what Jmeter has done to the result set. Does Jmeter just iterate through all rows? Does it fetch all columns values? Can I know which part of source code does Jmeter actually execute when calculating response time?
Basically everything is included, to wit:
Open (or get) the connection
Execute query
Close the connection
You can check the details in JDBCSampler.java or enable debug logging for JDBC protocol by adding the next line to user.properties file (lives in JMeter's "bin" folder)
log_level.jmeter.protocol.jdbc=DEBUG
or passing it to JMeter startup script via -J command-line argument as
jmeter -Jlog_level.jmeter.protocol.jdbc=DEBUG -n -t test.jmx ...
The whole ResultSet is being returned from the query to JMeter, you can work with it via JMeter Variables or scripting, see Debugging JDBC Sampler Results in JMeter guide for more details.

JMeter - saving results to both CSV and XML

What I try to achieve is to get JMeter results in 2 formats, for the same test execution. CSV is the one I'm mostly interested in, unless there are failures - then I may need to use data which can be saved only to XML. I can't use XML for most occasions, due to misc reasons.
I was looking at jmeter.save.saveservice.output_format cfg entry, it doesn't seem to accept both as valid entry. I was also looking at JMeter code itself, it also clearly separates both options.
Did anyone invent a hack to get both JMeter outputs at the same time?
Solution for both standalone JMeter and jmeter-maven-plugin is welcome.
If you use JMeter Maven plugin, as per Five Ways To Launch a JMeter Test without Using the JMeter GUI guide the default output has to be XML.
If you need CSV output as well - just add Simple Data Writer listener. If you looking for CSV data to be in line with JMeter default CSV values configure it as follows:

Resources