How to write Locust result of test api to file

Le Kim Trang picture Le Kim Trang · Jan 10, 2016 · Viewed 7k times · Source

I invoke the test through API,

locust -f locustfile.py --host=http://localhost --no-web  --hatch-rate=20 --clients=10000

and got a result

 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
 POST 8000/queries.json                                           137     0(0.00%)       5       2      23  |       5   11.00

--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                            708     0(0.00%)    

I would like to write this result to a file. Can anyone help me with this?

Below is the code in python

@task(1)
def test_topview(self):
    post_data_topview = """{ "category": "321",   "num": 20,   "genderCat" : ["23"] }"""
    with self.client.request(method="POST", url="http://192.168.1.107:8001/queries.json", headers= {"Content-Type" : "application/json"}, data = post_data_topview, catch_response = True ) as response:
        if not matched(response.content) :
            response.failure("No content")

Thank you very much.

Answer

Mesut GUNES picture Mesut GUNES · Jan 11, 2016

UPDATE

Saving csv file with the option --csv is added with this release . So you can run the following command to save result of the test as foo_requests.csv and foo_distribution.csv

locust -f locustfile.py --host=http://localhost --no-web  --hatch-rate=20 --clients=10000 --only-summary --csv=foo

FOR the version below 0.8

There has been a commit for saving the result of Locust but it is not merged to Locust yet. However you can update it manually with this commit. It is adding a new parameters as --statsfile=result.log to save the result.

Then the complete command should look like this

locust -f locustfile.py --host=http://localhost --no-web  --hatch-rate=20 --clients=10000 --only-summary --statsfile=result.log

You can check this post for updating Locust and checking the result of the log.