How to send test metrics to a prometheus remote write about each request made?

Could anybody please tell me how to send test metrics to a prometheus remote write about each request made, or just every second? So, I ran the test from the demo script for 30 secs, it produces 23 requests, but in the prometheus chart I see only 4 dots:


And here is the cli output:

But I want to get something like this:
image

With the xk6-dashboard is the same problem: How to see per-request chart for all generated requests? · grafana/xk6-dashboard · Discussion #90 · GitHub

I found a way how to export per-request metrics to a csv file, it just works by default using k6 run -o csv --duration 30s ./script.js:


But how to do this for prometheus, or, at least, for json?

@Murz

Just some ideas:

  • You could set K6_PROMETHEUS_RW_PUSH_INTERVAL=1s

  • You could set interval to 1s in the graph:
    Screenshot 2023-11-16 07:35:37

  • If you want to export metrics to json, then you can use --out json

Thanks for the ideas!

I already tried this but it just increases the sampling time from 5s to 1s, but still sends the aggregated data, so if in the one second, there were 7 requests, I will see only the average value.

If you want to export metrics to json, then you can use --out json

I tried this too, but in the resulting json file I see only the summary data, not per-request data, like in CSV.

So, the only way for now, that I found, is to parse the CSV (it’s not easy, cuz we should filter not only columns but also rows).

And, also, do the desired output programmatically in js, like this:

  console.log('\t' + i + '\t' + res.timings.waiting + '\t' + res.timings.duration);

and copy-paste it into Excel.

But I want to have fewer crutches, ideally - something out of the box!

@Murz

In the json output: “* type - can have the values Metric or Point where Metric means the line is declaring a metric, and Point is an actual data point (sample) for a metric.”

And I have another idea. You can write a custom ouput extension , or you can write a custom output plugin for the xk6-output-plugin where you can get all the sample point metrics.