how could i handle aggregated data myself in Locust?

Viewed 76

I want to print the individual parameters of the request result in my own format.I found the csv format only.How could I get each data in the code?Is there any event hooks can i use?

1 Answers

You can use event hooks. In the sample below, I have used the "quitting" event, but you can use any other hook appropriate for your use case.

class LoggedInUser(FastHttpUser):
host = "https://yourhost.com"
task_set = UserBehaviour

@events.quitting.add_listener
def do_checks(environment, **_kw):
    # doing aggregation on master node
    # if you want to run in all nodes remove this condition
    if isinstance(environment.runner, WorkerRunner): 
        return

    for x in environment.runner.stats.serialize_stats():
        name = x.get('name')
        total_response_time = float(x.get('total_response_time'))
        num_requests = int(x.get("num_requests"))
        min_response_time = float(x.get("min_response_time"))
        max_response_time = float(x.get("max_response_time"))
        average = total_response_time / num_requests
Related