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 d208867
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
35 changes: 33 additions & 2 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,42 @@ 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 = []
if csv_for_web_ui:
rows = [
','.join([
'"Type"',
'"Name"',
'"Timestamp"',
'"# requests"',
'"# failures"',
'"Requests/s"',
'"Requests Failed/s"',
'"Median response time"',
'"Average response time"',
'"Min response time"',
'"Max response time"',
'"Average Content Size"',
'"50%"',
'"66%"',
'"75%"',
'"80%"',
'"90%"',
'"95%"',
'"98%"',
'"99%"',
'"99.9%"',
'"99.99%"',
'"99.999"',
'"100%"'
])
]
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 d208867

Please sign in to comment.