Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom http_code stats #73

Closed
pixie79 opened this issue May 16, 2013 · 3 comments
Closed

Custom http_code stats #73

pixie79 opened this issue May 16, 2013 · 3 comments

Comments

@pixie79
Copy link

pixie79 commented May 16, 2013

Hi,

I have hacked up locust to provide me with some custom stats, so that I can count the different occurrences of certain status codes. So far I have this working well when running the process by itself however, If fails to give me the stats when running in distributed mode.

I guess I need to do something here to send the stats back from the slave to the master or for the master to recognise them. Would someone be able to point me in the correct direction please ?

Thanks

Mark

@heyman
Copy link
Member

heyman commented May 17, 2013

Hi!

You want to look at the locust.events.report_to_master and locust.events.slave_report event hooks (http://docs.locust.io/en/latest/api.html#locust.events.report_to_master).

The report_to_master is fired on slave nodes periodically and provides a dict where you can attach data which you will then be able to read out in the slave_report event listener on the master node.

Here's a small example:

def on_report_to_master(client_id, data):
    """ This method is fired periodically on the slave nodes """
    data["number_of_404"] = MyCustomStats.number_of_404
    # reset the number since it's aggregated on the master node
    MyCustomStats.number_of_404 = 0

def on_slave_report(client_id, data):
    """ This method id fired on the master node, every time a slave report comes in """
    MyCustomStats.number_of_404 += data["number_of_404"]

events.report_to_master += on_report_to_master
events.slave_report += on_slave_report

The stuff you put in the data dict, in your report_to_master listener, should be serializable by MessagePack (http://msgpack.org).

I hope this can be of help!

@heyman
Copy link
Member

heyman commented May 20, 2013

I'm closing this issue now, but feel free to re-open it if you need more pointers!

@heyman heyman closed this as completed May 20, 2013
@cscetbon
Copy link

cscetbon commented Nov 1, 2017

@pixie79 do you have an example on how you've done it in standalone mode. @heyman, is there an easy way to do it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants