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

Add failures csv download #999

Merged
merged 2 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,25 @@ def distribution_csv():
rows.append('"%s",0,"N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"' % s.name)

return "\n".join(rows)

def failures_csv():
""""Return the contents of the 'failures' tab as a CSV."""
from . import runners

rows = [
",".join((
'"Method"',
'"Name"',
'"Error"',
'"Occurences"',
))
]

for s in sort_stats(runners.locust_runner.stats.errors):
rows.append('"%s","%s","%s",%i' % (
s.method,
s.name,
s.error,
s.occurences,
))
return "\n".join(rows)
1 change: 1 addition & 0 deletions locust/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ <h2>Change the locust count</h2>
<div style="margin-top:20px;">
<a href="./stats/requests/csv">Download request statistics CSV</a><br>
<a href="./stats/distribution/csv">Download response time distribution CSV</a><br>
<a href="./stats/failures/csv">Download failures CSV</a><br>
<a href="./exceptions/csv">Download exceptions CSV</a>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def test_distribution_stats_csv(self):
# verify that the 95%, 98%, 99% and 100% percentiles are 1200
for value in total_cols[-4:]:
self.assertEqual('1200', value)

def test_failure_stats_csv(self):
stats.global_stats.log_error("GET", "/", Exception("Error1337"))
response = requests.get("http://127.0.0.1:%i/stats/failures/csv" % self.web_port)
self.assertEqual(200, response.status_code)

def test_request_stats_with_errors(self):
stats.global_stats.log_error("GET", "/", Exception("Error1337"))
Expand Down
11 changes: 10 additions & 1 deletion locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from . import runners
from .runners import MasterLocustRunner
from .stats import distribution_csv, median_from_dict, requests_csv, sort_stats
from .stats import distribution_csv, failures_csv, median_from_dict, requests_csv, sort_stats
from .util.cache import memoize

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -89,6 +89,15 @@ def distribution_stats_csv():
response.headers["Content-disposition"] = disposition
return response

@app.route("/stats/failures/csv")
def failures_stats_csv():
response = make_response(failures_csv())
file_name = "failures_{0}.csv".format(time())
disposition = "attachment;filename={0}".format(file_name)
response.headers["Content-type"] = "text/csv"
response.headers["Content-disposition"] = disposition
return response

@app.route('/stats/requests')
@memoize(timeout=DEFAULT_CACHE_TIME, dynamic_timeout=True)
def request_stats():
Expand Down