Context: I am trying to send my performance result to azure cosmos db using post call ,through the end point exposed and can be access by using the master key.
The JSON format of the payload is similarly like,
{
"id": "Project_Name",
"test_details": [
{ "test_Name": "APIM_Load_Test" },
{ "test_id": "Load_Test_01" }
],
"response_Details": [
{
"requestName": "sampleResult.getSampleLabel()",
"status": "status",
"responseTime": "sampleResult.getTime()",
"responsecode": "${(sampleResult.getResponseCode())}",
"sentBytes": "sampleResult.getSentBytes()",
"receivedBytes": "sampleResult.getBytesAsLong()",
"responseMessage": "${(sampleResult.getResponseMessage())}",
"samplecount": "sampleResult.getSampleCount()",
"errorCount": "sampleResult.getErrorCount()",
"time": "sampleResult.getTimeStamp()"
]
},
],
"thread_Details": { "number_vusers": "tc.activeThreads" }
}
Similarly, as we can do it to influx db by configuring JSR223 listener using groovy script as follow,
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.util.EntityUtils;
import org.apache.jmeter.threads.JMeterContextService;
try {
def tc = JMeterContextService.getThreadCounts();
def testStarted = props.get("testStarted");
def testEnded = props.get("testEnded");
int aThreads = tc.activeThreads;
int sThreads = tc.startedThreads;
int fThreads = tc.finishedThreads;
if ( testStarted == null && testEnded == null && aThreads >= 1 ){
Tests = new StringBuilder();
Tests.append("LoadTest")
.append(",testName=")
.append(args[0])
.append(",testId=")
.append(args[1])
.append(",testTriggeredBy=")
.append(args[2])
.append(",projectId=")
.append(args[3])
.append(" startTest=")
.append(vars.get("TESTSTART.MS"))
.append(",status=")
.append('"started"')
.append(" ")
.append(System.currentTimeMillis())
.append("000000");
props.put("testStarted","1");
PostMeasurement(Tests.toString());
}
if ( testStarted != null && testEnded == null && fThreads >= 1 ){
Teste = new StringBuilder();
Teste.append("LoadTest")
.append(",testName=")
.append(args[0])
.append(",testId=")
.append(args[1])
.append(",testTriggeredBy=")
.append(args[2])
.append(",projectId=")
.append(args[3])
.append(" endTest=")
.append(System.currentTimeMillis())
.append(",status=")
.append('"ended"')
.append(" ")
.append(System.currentTimeMillis())
.append("000000");
props.put("testEnded","1");
PostMeasurement(Tests.toString());
}
Threads = new StringBuilder();
Threads.append("Threads,")
.append("testId=")
.append(vars.get("TestId"))
.append(" activeThreads=")
.append(tc.activeThreads)
.append(" ")
.append(System.currentTimeMillis())
.append("000000");
PostMeasurement(Threads.toString());
} catch (Exception e) {
log.error("Error in Grafana Threads Listener : " +e );
}
void PostMeasurement(String Metric) {
def httpclient = new DefaultHttpClient(new BasicHttpParams());
def httpPost = new HttpPost();
httpPost.setURI(new URI(vars.get("InfluxDBAPI")));
httpPost.setEntity(new StringEntity(Metric));
HttpResponse response = httpclient.execute(httpPost);
EntityUtils.consumeQuietly(response.getEntity());
}