Stats in json to stdout (new command line option --json)#2269
Conversation
|
Nice! I think it makes more sense to send the output directly to stdout using print() instead of using logging. That removes the need to disable logging too. Can you also add a test case? (either an integration test in test_main.py, or in test_stats.py or whatever it is called) |
|
I think the user explicitly specifying |
30b6222 to
a70b3b5
Compare
|
I've made some integration tests, and deleted the part about skipping logging. Merry Christmas 🎄 |
|
Cool stuff, thanks! |
|
@cyberw @AndersSpringborg out of curiosity, why not matching ENV_VAR for this option? Any particular reason? Would a pr to add that be welcome? |

I extended the cli with a
--jsonargument. This argument prints the result of a run in json, after a run is finished. It blocks other INFO logs, so it's easy to interoperable with other programs. Below is an example withjq❯ python -m locust -f examples/locustfile.py --host http://localhost:80 --headless -u 10 -t 4s --json [ { "name": "/", "method": "GET", "last_request_timestamp": 1670363796.9102132, "start_time": 1670363793.665749, "num_requests": 8, "num_none_requests": 0, "num_failures": 0, "total_response_time": 61.882097012130544, "max_response_time": 18.852641980629414, "min_response_time": 3.2629000197630376, "total_content_length": 4920, "response_times": { "19": 1, "9": 1, "4": 3, "10": 1, "3": 1, "8": 1 }, "num_reqs_per_sec": { "1670363793": 1, "1670363794": 2, "1670363795": 1, "1670363796": 4 }, "num_fail_per_sec": {} } ]Locust: 2.13.2.dev11
Python: 3.10.8