Append completed counts to file

I’m wondering if anyone has an example out in the ether on how to create a simple text file that is just a list of starttime/endtime/VUs/completed iterations or something that I can use as a basis for that?

Hi @ShaneCourtrille

Welcome to the forum! Straight-forward way to do this would be to use execution API and simply output to console, e.g.:

import { sleep } from "k6";
import exec from "k6/execution";

function doIteration() {

export default function () {
    let startTime = new Date();
    let stopTime = new Date();

    console.log(exec.scenario.iterationInTest, exec.instance.vusActive, startTime.getTime(), stopTime.getTime());

k6 doesn’t support writing directly to files but you can store the console log with --console-output option to a file and then process it with some additional scripts as needs be.

If that isn’t enough, you can also take a look at this xk6 extension: GitHub - avitalique/xk6-file: k6 extension for writing files

I suppose, a bit nicer way of doing this would be to use metrics, esp. since number of VUs and iterations are already measured as metrics by default. But sadly, there is no way to filter out all the other metrics right now, details on that are here. But if in your use case presence of other metrics is not an issue, it makes sense to try out the -o csv option and see if that can be used too.

Hope that helps!