blob: 3c34697b34894e91524b6b99b9b0c7f4ea63d1b6 [file] [log] [blame]
Scott Baker771819b2014-03-19 22:10:17 -07001
2 <script type="text/javascript" src="//www.google.com/jsapi"></script>
3 <link rel="stylesheet" href="/static/hpc_historical.css">
4 <script type="text/javascript">
5 google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']});
6 </script>
Scott Bakerf842ce12014-03-27 09:05:15 -07007
Scott Baker771819b2014-03-19 22:10:17 -07008 <script type="text/javascript">
Scott Baker771819b2014-03-19 22:10:17 -07009
Scott Bakerf842ce12014-03-27 09:05:15 -070010 var queryString = "/analytics/bigquery/?sum=@bytes_sent&avg=@cpu&groupBy=Time,city,@hostname,@site";
11
12 var options = {
13 width: 600,
14 height: 400,
15 showRowNumber: false,
16 pages: true,
17 numRows: 9,
18 backgroundColor: "black"
19 };
20
21 // ask django for a data source URL to use for the graphs
22
23 function updateDataSourceUrl() {
24 $.ajax({
25 url: queryString,
26 dataType: 'json',
27 type: 'GET',
28 success: function (newData) {
29 sendAndDraw(newData["dataSourceUrl"])
30 }
31 });
32 }
33
34 TIME_COL = 0;
35 BANDWIDTH_COL = 2;
36 CPU_COL = 1;
37 CITY_COL = 3;
38 NODE_COL = 4;
39 SITE_COL = 5;
40
41 google.setOnLoadCallback(function () {
42 updateDataSourceUrl();
43 });
44
45 function showSiteTimeAgg(dt) {
46 var lineChart = new google.visualization.ChartWrapper({
47 'chartType': 'LineChart',
48 'containerId': 'chart4',
49 'options': {
50 'width': 300,
51 'height': 300,
52 'title': 'Network-wide usage',
53 'pages': true,
54 'numRows': 9
55 },
56 'view': {
57 'columns': [0, 1, 2]
58 }
59 });
60 lineChart.setDataTable(dt);
61 lineChart.draw();
62 }
63
64 function showSiteAgg(dt) {
65 var barChart = new google.visualization.ChartWrapper({
66 'chartType': 'ColumnChart',
67 'containerId': 'chart1',
68 'options': {
69 'width': 300,
70 'height': 300,
71 'title': 'Site-wise usage',
72 'pages': true,
73 'numRows': 9
74 },
75 'view': {
76 'columns': [1, 2, 3]
77 }
78 });
79 barChart.setDataTable(dt);
80 barChart.draw();
81 var geoChart = new google.visualization.ChartWrapper({
82 'chartType': 'GeoChart',
83 'containerId': 'chart2',
84 'options': {
85 'width': 300,
86 'height': 300,
87 'displayMode': 'markers',
88 'region': '021',
89 'title': 'Usage map',
90 colorAxis: {
91 colors: ['green', 'purple', 'red']
92 }
93 },
94 'view': {
95 'columns': [0, 2, 3]
96 }
97 });
98 geoChart.setDataTable(dt);
99 geoChart.draw();
100
101 var histogram = new google.visualization.ChartWrapper({
102 'chartType': 'Histogram',
103 'containerId': 'chart6',
104 'options': {
105 'width': 300,
106 'height': 300,
107 },
108 'title': 'Sites by load',
109 'view': {
110 'columns': [1, 2]
111 }
112 });
113 histogram.setDataTable(dt);
114 histogram.draw();
115
116 }
117
118 function handleResponse(response) {
119 var timeSlider = new google.visualization.ControlWrapper({
120 'controlType': 'DateRangeFilter',
121 'containerId': 'control1',
122 'options': {
123 'filterColumnLabel': 'Time',
124 ui: {
125 ticks: 10,
126 step: "minute"
127 }
128 }
129 });
130
131 // Define a bar chart
132 var barChart = new google.visualization.ChartWrapper({
133 'chartType': 'BarChart',
134 'containerId': 'chart1',
135 'options': {
136 'width': 400,
137 'height': 300,
138 'hAxis': {
139 'minValue': 0,
140 'maxValue': 60
141 },
142 'chartArea': {
143 top: 0,
144 right: 0,
145 bottom: 0
146 }
147 }
148 });
149
150 var categoryPicker = new google.visualization.ControlWrapper({
151 'controlType': 'CategoryFilter',
152 'allowMultiple': true,
153 'containerId': 'control2',
154 'options': {
155 'filterColumnLabel': 'site',
156 'ui': {
157 'labelStacking': 'vertical',
158 'allowTyping': false
159 }
160 }
161 });
162
163 var proxy = new google.visualization.ChartWrapper({
164 'chartType': 'Table',
165 'containerId': 'chart7',
166 'options': {
167 'width': 800,
168 'height': 300,
169 pageSize: 5,
170 page: 'enable',
171 'legend': 'none',
172 'title': 'Nodes'
173 },
174 'view': {
175 'columns': [0, 1, 2, 3, 4, 5]
176 }
177 });
178
179 function avg_bandwidth(arr) {
180 var ret = 0;
181 for (var i = 0; i < arr.length; i++) {
182 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
183 }
184 if (arr.length==0) {
185 return 0;
186 }
187 return ret/arr.length;
188 }
189
190 function sum_bytes_sent_as_bw(arr) {
191 var ret = 0;
192 for (var i = 0; i < arr.length; i++) {
193 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
194 }
195 return ret/60.0;
196 }
197
198 function sum_bytes_sent_as_GB(arr) {
199 var ret = 0;
200 for (var i = 0; i < arr.length; i++) {
201 ret+=arr[i]/1024.0/1024.0/1024.0;
202 }
203 return ret;
204 }
205
206 function fixDate2(unixDate) {
207 // not completely sure why we have to do this, as the data was in
208 // javascript Date() objects to start with. If we don't do it,
209 // then the horizontal axis will be blank.
210 return new Date(unixDate);
211 }
212
213 var format0dp = new google.visualization.NumberFormat({fractionDigits:0});
214 var format2dp = new google.visualization.NumberFormat({fractionDigits:2});
215
216 // Create a group for charts that will have a horizontal axis that is
217 // time.
218
219 google.visualization.events.addListener(proxy, 'ready', function () {
220 var dt = proxy.getDataTable();
221 var groupedData1 = google.visualization.data.group(dt, [{
222 column: TIME_COL,
223 type: 'datetime',
224 modifier: fixDate2,
225 }], [{
226 column: CPU_COL,
227 type: 'number',
228 label: "avg cpu",
229 aggregation: google.visualization.data.avg
230 }, {
231 column: BANDWIDTH_COL,
232 type: 'number',
233 label: "Gbps",
234 aggregation: sum_bytes_sent_as_bw
235 }]);
236
237 format0dp.format(groupedData1,1);
238 format2dp.format(groupedData1,2);
239
240 showSiteTimeAgg(groupedData1);
241 });
242
243 // Create a group for charts that will have a horizontal axis that is
244 // city or site.
245
246 google.visualization.events.addListener(proxy, 'ready', function () {
247 var dt = proxy.getDataTable();
248 var groupedData0 = google.visualization.data.group(dt, [CITY_COL, SITE_COL], [{
249 column: CPU_COL,
250 type: 'number',
251 label: 'avg cpu',
252 aggregation: google.visualization.data.avg
253 }, {
254 column: BANDWIDTH_COL,
255 type: 'number',
256 label: "GB sent",
257 aggregation: sum_bytes_sent_as_GB
258 }]);
259
260 format0dp.format(groupedData0,2);
261 format2dp.format(groupedData0,3);
262
263 showSiteAgg(groupedData0);
264 });
265
266 data = response.getDataTable();
267 new google.visualization.Dashboard(document.getElementById('dashboard')).
268 // Establish bindings, declaring the both the slider and the category
269 // picker will drive both charts.
270 bind([categoryPicker, timeSlider], [proxy]).
271 // Draw the entire dashboard.
272 draw(data);
273
274 }
275
276 function sendAndDraw(queryString) {
277 query = new google.visualization.Query(queryString)
278 query && query.abort();
279 query.send(function (response) {
280 handleResponse(response);
281 });
282 }
Scott Baker771819b2014-03-19 22:10:17 -0700283
284 </script>
285 <div id="dashboard" class="container">
286 <div class="row">
287 <div class="col-md-8">
288 <div class="col-md-4" id="control2"></div>
289 <div class="col-md-4" id="control1"></div>
290 <!--<div class="col-md-4" id="control3"></div>-->
291 </div>
292 </div>
293 <div class="row">
294 <div class="col-md-8">
295 <div class="col-md-4" id="chart1">
296 </div>
297 <div class="col-md-4" id="chart2">
298 </div>
299 <!--
300 <div class="col-md-4" id="chart3">
301 </div>-->
302 </div>
303 </div>
304 <div class="row">
305 <div class="col-md-8">
306 <div class="col-md-4" id="chart4">
307 </div>
308 <!--
309 <div class="col-md-4" id="chart5">
310 </div>-->
311 <div class="col-md-4" id="chart6">
312 </div>
313 </div>
314 </div>
315 </div>
316 <div id="chart7" style="display:none"></div>