Skip to content

Commit

Permalink
Make csv_history file available for download on web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mehta-ankit committed Dec 3, 2019
1 parent 44c3fff commit bd8e973
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,19 @@ def stats_history_csv_header():
'"100%"'
)) + '\n'

def stats_history_csv(stats_history_enabled=False):
def stats_history_csv(stats_history_enabled=False, csv_for_web_ui=False):
"""Returns the Aggregated stats entry every interval"""
from . import runners

rows = []
# csv_for_web_ui boolean returns the header along with the stats history row so that
# it can be returned as a csv for download on the web ui. Otherwise when run with
# the '--no-web' option we write the header first and then append the file with stats
# entries every interval.
if csv_for_web_ui:
rows = [stats_history_csv_header()]
else:
rows = []

timestamp = int(time.time())
stats_entries_per_iteration = []

Expand Down
2 changes: 1 addition & 1 deletion locust/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h2>Change the locust count</h2>
<div style="display:none;">
<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/stats_history/csv">Download response time stats history CSV</a><br>
<a href="./stats/failures/csv">Download failures CSV</a><br>
<a href="./exceptions/csv">Download exceptions CSV</a>
</div>
Expand Down
11 changes: 10 additions & 1 deletion locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from . import runners
from .runners import MasterLocustRunner
from .stats import failures_csv, median_from_dict, requests_csv, sort_stats
from .stats import failures_csv, median_from_dict, requests_csv, sort_stats, stats_history_csv
from .util.cache import memoize
from .util.rounding import proper_round

Expand Down Expand Up @@ -100,6 +100,15 @@ def request_stats_csv():
response.headers["Content-disposition"] = disposition
return response

@app.route("/stats/stats_history/csv")
def stats_history_stats_csv():
response = make_response(stats_history_csv(False, True))
file_name = "stats_history_{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/failures/csv")
def failures_stats_csv():
response = make_response(failures_csv())
Expand Down

0 comments on commit bd8e973

Please sign in to comment.