The capture functionality is great, and as a good enhancement it would be nice to include certain captured vars in the output.
Practical example: We output more timing information in a custom response header and would really like to have this captured during the load test so we can summarize/analyze it. I tried abusing the transform eval string but since it's sandboxed that's not possible :)
This can be done with a bit of custom Javascript, see this:
https://artillery.io/docs/testing_http.html#advanced-writing-custom-logic-in-javascript
You can console.log the values you're after, or alternatively the ee argument passed to hook functions has a customStat method, which can be used like this:
ee.emit('customStat', { stat: 'ResponseTime', value: 200 });
Which will then make Artillery print the distribution of ResponseTime values (p99, p95 etc) as part of its output to the terminal.
A more complete example from a recent project of mine which sounds similar to what you're trying to do:
function logXResponseTime(req, res, ctx, ee, done) {
if (!(res.headers['x-response-time'])) {
return done();
}
var responseTime = Number(
res.headers['x-response-time'].split('ms')[0]);
events.emit('customStat', { stat: 'response_time', value: responseTime });
return done();
}
That's awesome! Can't believe I missed that in the documentation since I was looking for that stuff specifically.
I'm only seeing the custom stats being output in the 10s reports and not the complete report at the end though. Missing a config flag? bug?
I'm only seeing the custom stats being output in the 10s reports and not the complete report at the end though. Missing a config flag? bug?
That's an oversight. The code is very experimental and needs to be rewritten to e.g. allow counters and not just histograms. I've created an issue here: https://github.com/shoreditch-ops/artillery/issues/161
Oh and you probably didn't miss that bit in the docs @dshook - I only added it the other day, it might not have been there when you were looking. :)
Haha, so that's why :) I'll close this issue and follow #161
Most helpful comment
This can be done with a bit of custom Javascript, see this:
https://artillery.io/docs/testing_http.html#advanced-writing-custom-logic-in-javascript
You can
console.logthe values you're after, or alternatively theeeargument passed to hook functions has acustomStatmethod, which can be used like this:Which will then make Artillery print the distribution of ResponseTime values (p99, p95 etc) as part of its output to the terminal.
A more complete example from a recent project of mine which sounds similar to what you're trying to do: