Getting request count from teardown

Hello,
I am trying out K6. I would like to get the number of requests that have been sent in the test from the teardown function, in order to have some custom checks at the end of the test.

Is it possible?

export function teardown(data) {
    const numberOfRequests = ?
}

In a related question, is it possible to get the value of metrics in the teardown function? If it was possible, I could simply take the value of the http_req metric.

Cheers,
Leon

Hi @leonpatmore :wave:

For various reasons, I’m afraid it is not possible to access the metrics values from the code at the moment.

If that’s an option available to you, I suggest you try the k6/experimental/redis module and store the value you’re interested in a local Redis instance. Another option would be to try the xk6-kv extension, which provides a cross-VU key-value store to use in your script.

Hope that’s helpful, let me know if you have further questions :bowing_man:

@leonpatmore You can access the metrics from the handleSummary()

export function handleSummary (data) {
  console.log('Request count:', data.metrics.http_reqs.values.count);
}

Does this suit your needs?

Thanks for the reply. I think by this point it it might be too late, as I would like to use the request count at the end of the test to do some checks (which I guess is not possible in the summary).
Cheers