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

Support for custom time metrics #243

Closed
mdomans opened this issue Feb 12, 2015 · 3 comments
Closed

Support for custom time metrics #243

mdomans opened this issue Feb 12, 2015 · 3 comments

Comments

@mdomans
Copy link

mdomans commented Feb 12, 2015

Hi, recently I needed to load test an elasticsearch cluster and for what it's worth, I wasn't interested in connection time, only in the work time spent by the ES server. Elasticsearch returns that data as part of a JSON response, under a took key. I wanted to measure that, so I hacked this:

if response.status_code not in [200, 300, 301, 302, 303]:
    response.failure("Status different from 200")
else:
    resp = json.loads(response.content)
    events.request_success.fire(
        request_type=response.locust_request_meta["method"],
        name=response.locust_request_meta["name"],
        response_time=resp['took'],
        response_length=response.locust_request_meta["content_size"],
    )
    response._is_reported = True

I think it could be wrapped in something much nicer, e.g.:

if response.status_code not in [200, 300, 301, 302, 303]:
    reporting.record_failure(response)
else:
    reporting.record_success(response, took=10)

I was interested if anyone else is interested in being added to locust

@heyman
Copy link
Member

heyman commented Feb 13, 2015

Hi!

Rather than modifying Locust, I would probably write a small custom client (which wraps python-requests or some other HTTP client) that fires the request_success & request_failure events.

I'm not sure I understand what you're proposing. Is it the API for fire:ing request_success/request_failure that you think could be simplified?

@mdomans
Copy link
Author

mdomans commented Feb 13, 2015

I think I understand your approach better now. I think you lack good docs on how one should approach doing such custom stuff, though I've got the idea now how to port my code. Can I contribute it as an example?

@justiniso
Copy link
Member

@mdomans yes, definitely!

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