From d208867ca34401b97795516319823e529ad10cd2 Mon Sep 17 00:00:00 2001 From: Ankit Mehta Date: Tue, 3 Dec 2019 14:22:48 -0500 Subject: [PATCH] Make csv_history file available for download on web UI --- locust/stats.py | 35 +++++++++++++++++++++++++++++++++-- locust/templates/index.html | 2 +- locust/web.py | 11 ++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/locust/stats.py b/locust/stats.py index 200bbc2694..a954762066 100644 --- a/locust/stats.py +++ b/locust/stats.py @@ -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 = [] diff --git a/locust/templates/index.html b/locust/templates/index.html index a19bfa68ff..a394221890 100644 --- a/locust/templates/index.html +++ b/locust/templates/index.html @@ -157,7 +157,7 @@

Change the locust count

Download request statistics CSV
- Download response time distribution CSV
+ Download response time stats history CSV
Download failures CSV
Download exceptions CSV
diff --git a/locust/web.py b/locust/web.py index ec7034b5ce..b90c8b6365 100644 --- a/locust/web.py +++ b/locust/web.py @@ -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 @@ -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())