-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
203 lines (198 loc) · 8.42 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script src="http://yui.yahooapis.com/3.8.0/build/yui/yui-min.js"></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['corechart', 'gauge']});
</script>
<script type='text/javascript'>
YUI().use("node", "io", "io-form", "event", "dump", "json-parse", "button", function(Y) {
var that = this;
var running = false;
var gauge_options = {
width: 200, height: 200,
redFrom: 0, redTo: 10,
yellowFrom: 10, yellowTo: 50,
greenFrom: 50, greenTo: 100,
minorTicks: 6,
};
var chart_options = {
width: 600, height: 200,
title : 'Megabits / Second',
animation : { duration : 500 },
};
var upgauge = new google.visualization.Gauge(Y.one('#upgauge').getDOMNode());
var dngauge = new google.visualization.Gauge(Y.one('#dngauge').getDOMNode());
var upchart = new google.visualization.LineChart(Y.one('#upchart').getDOMNode());
var dnchart = new google.visualization.LineChart(Y.one('#dnchart').getDOMNode());
var dtable = new google.visualization.DataTable();
var lUp = 0, lDown = 0;
dtable.addColumn('timeofday', 'Time');
dtable.addColumn('number', 'Bitrate');
upchart.draw(dtable, chart_options);
dnchart.draw(dtable, chart_options);
upgauge.draw(google.visualization.arrayToDataTable([['Label', 'Value'], ['Upload', 0]]), gauge_options);
dngauge.draw(google.visualization.arrayToDataTable([['Label', 'Value'], ['Download', 0]]), gauge_options);
var onSuccess = function (id, o, args) {
dtable = new google.visualization.DataTable();
dtable.addColumn('timeofday', 'Time');
dtable.addColumn('number', 'Bitrate');
Y.one('#status_div').setHTML("<i>Starting...</i>");
Y.all('#tstreqform input').setAttribute('disabled', 'disabled');
Y.later(250, that, updateVisuals, false); // give it time so that GET "/stats" doesn't fail right away
};
var onFailure = function (id, o, args) {
Y.one('#start').removeAttribute('disabled');
Y.all('#tstreqform input').removeAttribute('disabled');
running = false;
Y.one('#params_div').setStyle('opacity', '');
}
var enableForm = function () {
Y.one('#start').removeAttribute('disabled');
Y.all('#tstreqform input').removeAttribute('disabled');
running = false;
Y.one('#params_div').setStyle('opacity', '');
};
Y.one('#start').on('click', function(e) {
if (running) return;
Y.one('#start').setAttribute('disabled', 'disabled');
running = true;
Y.one('#params_div').setStyle('opacity', '0.4');
e.halt(true);
var cfg = {
method : "POST",
form : { id : Y.one('#tstreqform'), useDisabled : false },
on : { success : onSuccess , failure : onFailure },
context : Y,
arguments : { success : '/cmd' },
};
Y.io("/cmd", cfg);
});
enableForm();
/*
Y.one('#stop').on('click', function(e) {
var cfg = { method : "POST", data : "tstt=STOP" }
Y.io("/cmd", cfg);
});
*/
var updateVisuals = function () {
Y.io("/stats", {
on : {
success : function (tx, r) {
var pr;
try {
pr = Y.JSON.parse(r.responseText);
} catch (e) {
alert("JSON Parse failed: ", r.responseText);
Y.one('#status_div').setHTML("<i>Error: "+e+"</i>");
enableForm();
return;
}
var msg = pr.Stat + " " + ((pr.Type=="UP")?"Upload":((pr.Type=="DOWN")?"Download":''));
Y.one('#status_div').setHTML("<i>"+msg+"</i>");
if (pr.Stat != "Running") {
enableForm();
return;
}
var foo = new Date();
var xtm = [foo.getHours(), foo.getMinutes(), foo.getSeconds(), foo.getMilliseconds()];
dtable.addRows([[xtm, pr.Rate]]);
if (pr.Type == "UP") {
upchart.draw(dtable, chart_options);
lUp = pr.Rate;
var dt = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Upload', lUp ]
]);
upgauge.draw(dt, gauge_options);
} else {
dnchart.draw(dtable, chart_options);
lDown = pr.Rate;
var dt = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Download', lDown ]
]);
dngauge.draw(dt, gauge_options);
}
Y.later(500, that, updateVisuals, false);
},
failure : function (tx, r) {
alert("No data");
enableForm();
},
},
});
};
});
</script>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.8.0/build/cssfonts/cssfonts-min.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.8.0/build/cssgrids/grids-min.css">
</head>
<body>
<div> <!-- class="yui3-cssfonts"> -->
<h1>tcpmeter - TCP Speedometer</h1>
<div class="yui3-skin-sam">
<div class="yui3-g">
<div id="params_div" class="yui3-u-1-4">
<form id="tstreqform" method="post" action="/cmd">
<fieldset>
<legend>Server Information</legend>
<p>
<label>Host:<input type=text name=raddr required></label><br />
<label>RPC:<input type=number name=rport default="8001" placeholder="8001" required></label>
</p>
</fieldset>
<p>
<fieldset>
<legend>Packet Type</legend>
<p>
<input type=radio name=pktt value="udp" disabled="disabled">UDP</input>
<input type=radio name=pktt value="tcp" checked="checked">TCP</input>
</p>
</fieldset>
</p>
<p>
<fieldset>
<legend>Type of Measurement</legend>
<p>
<input type=radio name=tstt value="UP" checked="checked">Upload</input>
<input type=radio name=tstt value="DOWN">Download</input>
<input type=radio name=tstt value="RTT">Round Trip</input><br />
<input type=checkbox name=txcont checked="">Continuous</input>
</p>
</fieldset>
</p>
<p>
<fieldset>
<legend>Size of Dataset</legend>
<p>
<label>Amount of data:<input type=number name=txsize></label><br />
<input type=radio name=txmult value="KB">KB</input>
<input type=radio name=txmult value="MB" checked="checked">MB</input>
<input type=radio name=txmult value="GB">GB</input>
</p>
</fieldset>
</p>
</form>
<p>
<input id="start" type="button" value="Start" />
<!-- <input id="stop" type="button" value="Abort" /> -->
</p>
</div>
<div class="yui3-u-3-4">
<div class="yui3-g">
<div class="yui3-u-1-4" id='upgauge'></div>
<div class="yui3-u-3-4" id='upchart'></div>
</div>
<div class="yui3-g">
<div class="yui3-u-1-4" id='dngauge'></div>
<div class="yui3-u-3-4" id='dnchart'></div>
</div>
<div id='status_div' style="text-align:center"><p><i>Stopped</i></p></div>
</div>
</div>
</div>
</div>
</body>
</html>