Locust: How to retrieve host argument for custom client

Created on 1 Feb 2015  路  2Comments  路  Source: locustio/locust

Hi,

I have developed a custom client and would like to use the host variable that can be passed on the command line when starting locust when instantiating my custom class

locust --host=http://example.com -f locustfile.py

I have interrogated the Locust object in my custom class without success.

class CustomClientLocust(Locust):
    def __init__(self):
         super(CustomClientLocust, self).__init__()
         print str(Locust.__dict__)
         hostname = Locust.host
         self.client = MyCustomClient(hostname)

I can see that the options.host argument is set in the LocustRunner class, but we don't seem to have access to this in the Locust file?

Any tips on where I should be looking would be gratefully received!

Thanks!

Most helpful comment

OK I found a solution. If you are subclassing Locust then you can access host using self.host.
If you are subclassing a TaskSet then you can access host using self.parent.host.

Hope this help!

All 2 comments

:+1:

I have the same need but I cannot find a way to retrieve the host option. I checked main.py but apparently the options object is not stored in a location I can access from my TaskSet.

OK I found a solution. If you are subclassing Locust then you can access host using self.host.
If you are subclassing a TaskSet then you can access host using self.parent.host.

Hope this help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bgenchel picture bgenchel  路  3Comments

gboorse picture gboorse  路  3Comments

ashleigh-robinson picture ashleigh-robinson  路  3Comments

radiantone picture radiantone  路  3Comments

meeech picture meeech  路  4Comments