locust icon indicating copy to clipboard operation
locust copied to clipboard

export the results as a json file

Open kasir-barati opened this issue 9 months ago • 2 comments

Prerequisites

Description

Hi,

When I run locust --help I can see that we are allowed to pass --json as a flag to see the result of tests as a JSON, but what I need is to store that json in a file. Is it possible to implement this feature?

I know for csv you can pass a filename and it will store the result in that file but this is not the case for json which makes me wonder why not? It should be almost the same as csv IMO.

$ locust --help
# ...
Request statistics options:
  --csv <filename>      Store request stats to files in CSV format. Setting this option will generate three files: <filename>_stats.csv, <filename>_stats_history.csv and
                        <filename>_failures.csv. Any folders part of the prefix will be automatically created
  --csv-full-history    Store each stats entry in CSV format to _stats_history.csv file. You must also specify the '--csv' argument to enable this.
  --print-stats         Enable periodic printing of request stats in UI runs
  --only-summary        Disable periodic printing of request stats during --headless run
  --reset-stats         Reset statistics once spawning has been completed. Should be set on both master and workers when running in distributed mode
  --html <filename>     Store HTML report to file path specified. Able to parse certain tags - {u}, {r}, {t} and convert them to number of users, spawn rate and run time
                        respectively.
  --json                Prints the final stats in JSON format to stdout. Useful for parsing the results in other programs/scripts. Use together with --headless and --skip-log
                        for an output only with the json data.
# ...

kasir-barati avatar Apr 04 '25 12:04 kasir-barati

I guess we could support a filename there as well. But you can just do locust --json > myfile.json

cyberw avatar Apr 04 '25 12:04 cyberw

It would nice to have the json argument accept a filename because redirecting the stdout to a json file requires that you use --skip-log to make sure the output is valid json. In a CICD pipeline, for example, you still want to show the relevant log statements, but then want to upload the final result file afterwards.

Cnoor0171 avatar Apr 22 '25 21:04 Cnoor0171

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 20 days.

github-actions[bot] avatar Jun 22 '25 02:06 github-actions[bot]

Thanks for adding --json-file <filename> option to Locust CLI 💮.

Just for anybody who wants to read the docs about this: https://docs.locust.io/en/stable/configuration.html#command-line-options

kasir-barati avatar Jun 22 '25 12:06 kasir-barati