Reputation: 3
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.
Upvotes: 0
Views: 1471
Reputation: 168002
I'm not too sure whether you will be able to distinguish ip1 or ip2 incormation, however.
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.
Upvotes: 1