K6 metrics logging JSON

Hello everyone, i’m trying to figure out how can I save every time stamp to the metrics for end result, or at-least somehow save timestamps so once I create json file instead of summary result timestamps would be there for each iteration or each http request. As far as I tried nothing works, the only part I can logged the timestamps to console but not end summary json file

Hi @sillymoomoo , welcome to the community forum :tada:

Not certain I understood what you want, but it seems like you just want to use the JSON output :thinking:

If not, can you explain in more detail what you would like to achieve, preferably with an example.

@mstoykov Hey! thanks for reply!
Alright so what I want in real life scenario is to get get json output with the timestamps so I could create a graph dashboard.
For that I am using infinity plugin for reading json format.
The plugin cant handle the json output when there is multiple objects, but only one object.
So I was thinking is there a way to get all timestamps from k6 test for each iteration so I could monitor which iteration/http request took which time to be handled.
I can log timestamps or date when was the iteration/httpreq done but only to console, and the metrics that K6 provides dont really show or provide a way to log timestamps to the json, as Trend, Gauge, Rate and Counter only provide sum or avg or last etc.

So what I am looking for is logging timestamps of each http req/iteration so I could parse it from json and create a nice dashboard :slight_smile: , let me know if more explanation required :slight_smile:

import http from "k6/http";
import { sleep } from "k6";
import { check } from "k6";

export function handleSummary(data) {
  return {
    [`${new Date().toISOString()}_summary.json`]: JSON.stringify(data, null, 4),

export let options = {
  insecureSkipTLSVerify: true,
  noConnectionReuse: false,
  vus: 1, // Virtual users
  duration: "10s", // duration of test
  summaryTimeUnit: "s",

export default () => {
  const response = http.get(randomApiHere);

  check(response, {
    "status is 200 -- OK": (r) => r.status === 200,

And I want to use in tests for example new Date() - new Date(exec.scenario.startTime) to know when the requests happening

JSON output which you suggested is not really working for me, as the plugin does not handle multiple objects from json file.

Unless there is a better plugin or way to parse JSON to grafana which I am not away of :smiley:

It seems to me that you should write something to parse and change the JSON output or … better (IMO) output metrics to something like statsd/influxdb/cortex/mimir and use grafana to read from it instead of from a JSON file.

As you have probably found there is no way to write arbitrary data to files during the file execution. The handleSummary is more or less the only way and it has only the summary.

Thanks for your time I will consider your options :slight_smile: