'which beanshell code or groovy code are used to to push the jtl results to db by using single one sampler

In jmeter,I want the results while the running the test,which beansheel code add to sampler and convert summary report values in to milliseconds and push those values in MySQL db automatically by adding one sampler. please give me step by step process and all possible ways explain

and how create a table in particular values on jtl file values in avg,min,max,response time,error values in mysql db please explain



Solution 1:[1]

Wouldn't that be easier to use InfluxDB instead? JMeter provides Backend Listener which automatically sends metrics to InfluxDB and they can be visualized via Grafana. Check out How to Use Grafana to Monitor JMeter Non-GUI Results - Part 2 article for more details.


If you have to use MySQL the correct approach would be writing your own implementation of the AbstractBackendListenerClient


If you need a "single sampler" - take a look at JSR223 Listener, it has prev shorthand for SampleResult class instance providing access to all the necessary information like:

def name = prev.getSampleLabel() // get sampler name
def elapsed = prev.getTime()     // get elapsed time (in milliseconds)
// etc.

and in order to insert them into the database you could do something like:

import groovy.sql.Sql

def url = 'jdbc:mysql://localhost:3306/your-database'
def user = 'your-username'
def password = 'your-password'
def driver = 'com.mysql.cj.jdbc.Driver'
def sql = Sql.newInstance(url, user, password, driver)

def insertSql = 'INSERT INTO your-table-name (sampler, elapsed) VALUES (?,?)'
def params = [name , elapsed]
def keys = sql.executeInsert insertSql, params

sql.close()    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1