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']});
8 <script type="text/javascript">
16 backgroundColor: "black"
19 // ask django for a data source URL to use for the graphs
21 function updateDataSourceUrl() {
22 var sliceName = $("#historical_slicename :selected").text();
23 var queryString = "/analytics/bigquery/?timeBucket=600&maxAge=86400&sum=@bytes_sent&avg=@cpu&groupBy=Time,city,@hostname,@site&slice=" + sliceName;
29 success: function (newData) {
30 sendAndDraw(newData["dataSourceUrl"])
42 google.setOnLoadCallback(function () {
43 $('#historical_slicename').change(function()
45 updateDataSourceUrl();
48 updateDataSourceUrl();
51 function showSiteTimeAgg(dt) {
52 var lineChart = new google.visualization.ChartWrapper({
53 'chartType': 'LineChart',
54 'containerId': 'chart-site-time',
58 'title': 'Network-wide usage',
66 lineChart.setDataTable(dt);
70 function showSiteAgg(dt) {
71 var barChart = new google.visualization.ChartWrapper({
72 'chartType': 'ColumnChart',
73 'containerId': 'chart-site-agg',
77 'title': 'Site-wise usage',
85 barChart.setDataTable(dt);
87 var geoChart = new google.visualization.ChartWrapper({
88 'chartType': 'GeoChart',
89 'containerId': 'chart-geo',
93 'displayMode': 'markers',
97 colors: ['green', 'purple', 'red']
104 geoChart.setDataTable(dt);
107 /* var histogram = new google.visualization.ChartWrapper({
108 'chartType': 'Histogram',
109 'containerId': 'chart-histo',
114 'title': 'Sites by load',
119 histogram.setDataTable(dt);
124 function handleResponse(response) {
125 var timeSlider = new google.visualization.ControlWrapper({
126 'controlType': 'DateRangeFilter',
127 'containerId': 'control1',
129 'filterColumnLabel': 'Time',
137 var categoryPicker = new google.visualization.ControlWrapper({
138 'controlType': 'CategoryFilter',
139 'allowMultiple': true,
140 'containerId': 'control2',
142 'filterColumnLabel': 'site',
144 'labelStacking': 'vertical',
150 var proxy = new google.visualization.ChartWrapper({
151 'chartType': 'Table',
152 'containerId': 'chart7',
162 'columns': [0, 1, 2, 3, 4, 5]
166 function avg_bandwidth(arr) {
168 for (var i = 0; i < arr.length; i++) {
169 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
174 return ret/arr.length;
177 function sum_bytes_sent_as_bw(arr) {
179 for (var i = 0; i < arr.length; i++) {
180 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
185 function sum_bytes_sent_as_GB(arr) {
187 for (var i = 0; i < arr.length; i++) {
188 ret+=arr[i]/1024.0/1024.0/1024.0;
193 function fixDate2(unixDate) {
194 // not completely sure why we have to do this, as the data was in
195 // javascript Date() objects to start with. If we don't do it,
196 // then the horizontal axis will be blank.
197 return new Date(unixDate);
200 var format0dp = new google.visualization.NumberFormat({fractionDigits:0});
201 var format2dp = new google.visualization.NumberFormat({fractionDigits:2});
203 // Create a group for charts that will have a horizontal axis that is
206 google.visualization.events.addListener(proxy, 'ready', function () {
207 var dt = proxy.getDataTable();
208 var groupedData1 = google.visualization.data.group(dt, [{
216 aggregation: google.visualization.data.avg
218 column: BANDWIDTH_COL,
221 aggregation: sum_bytes_sent_as_bw
224 format0dp.format(groupedData1,1);
225 format2dp.format(groupedData1,2);
227 showSiteTimeAgg(groupedData1);
230 // Create a group for charts that will have a horizontal axis that is
233 google.visualization.events.addListener(proxy, 'ready', function () {
234 var dt = proxy.getDataTable();
235 var groupedData0 = google.visualization.data.group(dt, [CITY_COL, SITE_COL], [{
239 aggregation: google.visualization.data.avg
241 column: BANDWIDTH_COL,
244 aggregation: sum_bytes_sent_as_GB
247 format0dp.format(groupedData0,2);
248 format2dp.format(groupedData0,3);
250 showSiteAgg(groupedData0);
253 data = response.getDataTable();
254 new google.visualization.Dashboard(document.getElementById('dashboard')).
255 // Establish bindings, declaring the both the slider and the category
256 // picker will drive both charts.
257 bind([categoryPicker, timeSlider], [proxy]).
258 // Draw the entire dashboard.
263 function sendAndDraw(queryString) {
264 query = new google.visualization.Query(queryString)
265 query && query.abort();
266 query.send(function (response) {
267 handleResponse(response);
272 <div id="dashboard" class="graph_container">
274 <span><b>Slice Name:</b></span>
275 <span><select id="historical_slicename">
276 {% for slice in userSliceInfo %}
277 <option value="{{ slice.slicename }}">{{ slice.slicename }}</option>
281 <div class="row" dstyle="background-color:red">
282 <div class="col-md-12">
283 <div class="col-md-4" id="control2"></div>
284 <div class="col-md-4" id="control1"></div>
285 <!--<div class="col-md-4" id="control3"></div>-->
288 <div class="row" dstyle="background-color:green">
289 <div class="col-md-12">
290 <div class="col-md-fullgraph" id="chart-site-agg" dstyle="background-color:pink">
294 <div class="row" dstyle="background-color:blue">
295 <div class="col-md-12">
296 <div class="col-md-halfgraph" id="chart-site-time" dstyle="background-color:orange">
298 <div class="col-md-halfgraph" id="chart-geo" dstyle="background-color:yellow">
303 <div id="chart7" style="display:none"></div>