Skip to content

Commit

Permalink
Merge pull request locustio#4 from erlanggakrisnamukti/rizalfr/f_modi…
Browse files Browse the repository at this point in the history
…fy_param

add timer to header of locust
  • Loading branch information
pancaprima authored Sep 27, 2017
2 parents 588aa0f + e67229f commit e16676e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion locust/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ a:hover {
.running .start, .hatching .start {display: none;}

.ready .edit {display: none;}
.ready .start {display: block;}
.ready .start {display: inline;}

.running .status, .hatching .status {display: block;}
.stopped .status {display: block;}
Expand Down
48 changes: 43 additions & 5 deletions locust/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@
<div class="value"><span id="fail_ratio"></span>%</div>
</div>
<div class="top_box box_stop box_running" id="box_stop">
<a href="/stop" class="stop-button"><i></i>STOP</a>
<a href="/stop" class="stop-button" onclick="stopClock()""><i></i>STOP</a>
<a href="/stats/reset" class="reset-button">Reset<br>Stats</a>
</div>
<div class="top_box box_timer box_running" id="box_timer">
<div class="label">TIMER</div>
<div class="value"><label id="minutes">00</label>:<label id="seconds">00</label></div>
</div>
</div>
<div style="clear:both;"></div>
</div>
Expand All @@ -59,8 +63,7 @@
</div>
<div class="padder">
<h2>Start new Locust swarm</h2>
<form action="/swarm" method="POST" id="swarm_form">
<label for="locust_count">Number of users to simulate</label>
<form action="/swarm" method="POST" id="swarm_form" onsubmit="startAndReset()">
<input type="text" name="locust_count" id="locust_count" class="val" /><br>
<label for="hatch_rate">Hatch rate <span style="color:#8a8a8a;">(users spawned/second)</span></label>
<input type="text" name="hatch_rate" id="hatch_rate" class="val" /><br>
Expand All @@ -83,7 +86,7 @@ <h2>Start new Locust swarm</h2>
</div>
<div class="padder">
<h2>Change the locust count</h2>
<form action="/swarm" method="POST" id="edit_form">
<form action="/swarm" method="POST" id="edit_form" onsubmit="startClock()">
<label for="locust_count">Number of users to simulate</label>
<input type="text" name="locust_count" id="new_locust_count" class="val" /><br>
<label for="hatch_rate">Hatch rate <span style="color:#8a8a8a;">(users spawned/second)</span></label>
Expand All @@ -101,7 +104,7 @@ <h2>Change the locust count</h2>
</div>
<div class="padder">
<h2>Ramping</h2>
<form action="/ramp" method="POST" id="ramp_form">
<form action="/ramp" method="POST" id="ramp_form" onsubmit="startAndReset()">
<div style="float:left;">
<label for="init_count" title="This is the number of initial number of locusts that will be spawned. Pick a number you know can be handled.">Initial number of clients</label>
<input type="text" name="init_count" id="init_count" class="val" /><br>
Expand Down Expand Up @@ -287,5 +290,40 @@ <h1>Version</h1>
</script>
<script type="text/javascript" src="/static/chart.js?v={{ version }}"></script>
<script type="text/javascript" src="/static/locust.js?v={{ version }}"></script>
<script type="text/javascript">

var clicked = false;
var sec = 0;

function startAndReset(){
startClock();
resetClock();
}
function startClock() {
if (clicked === false) {
clock = setInterval("stopWatch()", 1000);
clicked = true;;
}
else if (clicked === true) {
}
}
function stopWatch() {
document.getElementById("seconds").innerHTML = ++sec%60;
document.getElementById("minutes").innerHTML = parseInt(sec/60,10);
console.log(sec);
}
function stopClock() {
window.clearInterval(clock);
console.log(clock);
document.getElementById("seconds").innerHTML = sec%60;
document.getElementById("minutes").innerHTML = parseInt(sec/60,10);
clicked = false;
}
function resetClock(){
sec = 0;
document.getElementById("seconds").innerHTML = 0;
document.getElementById("minutes").innerHTML = 0;
}
</script>
</body>
</html>
24 changes: 12 additions & 12 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def index():
host = runners.locust_runner.locust_classes[0].host
else:
host = None

return render_template("index.html",
state=runners.locust_runner.state,
is_distributed=is_distributed,
Expand Down Expand Up @@ -76,7 +76,7 @@ def stop():
def reset_stats():
runners.locust_runner.stats.reset_all()
return "ok"

@app.route("/stats/requests/csv")
def request_stats_csv():
rows = [
Expand All @@ -87,13 +87,13 @@ def request_stats_csv():
'"# failures"',
'"Median response time"',
'"Average response time"',
'"Min response time"',
'"Min response time"',
'"Max response time"',
'"Average Content Size"',
'"Requests/s"',
])
]

for s in chain(_sort_stats(runners.locust_runner.request_stats), [runners.locust_runner.stats.aggregated_stats("Total", full_request_history=True)]):
rows.append('"%s","%s",%i,%i,%i,%i,%i,%i,%i,%.2f' % (
s.method,
Expand Down Expand Up @@ -170,22 +170,22 @@ def request_stats():
if stats:
report["total_rps"] = stats[len(stats)-1]["current_rps"]
report["fail_ratio"] = runners.locust_runner.stats.aggregated_stats("Total").fail_ratio

# since generating a total response times dict with all response times from all
# urls is slow, we make a new total response time dict which will consist of one
# entry per url with the median response time as key and the number of requests as
# value
response_times = defaultdict(int) # used for calculating total median
for i in xrange(len(stats)-1):
response_times[stats[i]["median_response_time"]] += stats[i]["num_requests"]

# calculate total median
stats[len(stats)-1]["median_response_time"] = median_from_dict(stats[len(stats)-1]["num_requests"], response_times)

is_distributed = isinstance(runners.locust_runner, MasterLocustRunner)
if is_distributed:
report["slave_count"] = runners.locust_runner.slave_count

report["state"] = runners.locust_runner.state
report["user_count"] = runners.locust_runner.user_count
return json.dumps(report)
Expand All @@ -195,9 +195,9 @@ def exceptions():
response = make_response(json.dumps({
'exceptions': [
{
"count": row["count"],
"msg": row["msg"],
"traceback": row["traceback"],
"count": row["count"],
"msg": row["msg"],
"traceback": row["traceback"],
"nodes" : ", ".join(row["nodes"])
} for row in six.itervalues(runners.locust_runner.exceptions)
]
Expand All @@ -213,7 +213,7 @@ def exceptions_csv():
for exc in six.itervalues(runners.locust_runner.exceptions):
nodes = ", ".join(exc["nodes"])
writer.writerow([exc["count"], exc["msg"], exc["traceback"], nodes])

data.seek(0)
response = make_response(data.read())
file_name = "exceptions_{0}.csv".format(time())
Expand Down

0 comments on commit e16676e

Please sign in to comment.