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