Hi,
Is there a way to access the built-in metrics during test execution so I can put some logic if certain criterias as met.
For example, I need to stop the test execution if I have reached 100k http reqs, in this case I need to access the http_reqs metric!
Hi @rdt.one!
I don’t think, you can access it by default, but you can definitely do it with an extension.
PoC:
With this extension GitHub - bandorko/xk6-metrics
You can access the needed information like this:
import http from 'k6/http';
import metrics from 'k6/x/metrics';
export const options = {
discardResponseBodies: true,
scenarios: {
scenario1: {
executor: 'shared-iterations',
vus: 1,
iterations: '10',
},
},
};
const httpReqs = metrics.registry.get('http_reqs');
export default function () {
http.get('https://test.k6.io/');
console.log('http_reqs:' + httpReqs.sink.value);
}