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;
25 $( "#control1").html("");
26 $( "#control2").html("");
27 $( "#chart-site-agg" ).html("<div class='loading'>Loading ...</div>");
28 $( "#chart-site-time" ).html("");
29 $( "#chart-geo" ).html("");
35 success: function (newData) {
36 sendAndDraw(newData["dataSourceUrl"])
48 google.setOnLoadCallback(function () {
49 $('#historical_slicename').change(function()
51 updateDataSourceUrl();
54 updateDataSourceUrl();
57 function showSiteTimeAgg(dt) {
58 var lineChart = new google.visualization.ChartWrapper({
59 'chartType': 'LineChart',
60 'containerId': 'chart-site-time',
64 'title': 'Network-wide usage',
72 lineChart.setDataTable(dt);
76 function showSiteAgg(dt) {
77 var barChart = new google.visualization.ChartWrapper({
78 'chartType': 'ColumnChart',
79 'containerId': 'chart-site-agg',
83 'title': 'Site-wise usage',
91 barChart.setDataTable(dt);
93 var geoChart = new google.visualization.ChartWrapper({
94 'chartType': 'GeoChart',
95 'containerId': 'chart-geo',
99 'displayMode': 'markers',
101 'title': 'Usage map',
103 colors: ['green', 'purple', 'red']
110 geoChart.setDataTable(dt);
114 function handleResponse(response) {
115 var timeSlider = new google.visualization.ControlWrapper({
116 'controlType': 'DateRangeFilter',
117 'containerId': 'control1',
119 'filterColumnLabel': 'Time',
127 var categoryPicker = new google.visualization.ControlWrapper({
128 'controlType': 'CategoryFilter',
129 'allowMultiple': true,
130 'containerId': 'control2',
132 'filterColumnLabel': 'site',
134 'labelStacking': 'vertical',
140 var proxy = new google.visualization.ChartWrapper({
141 'chartType': 'Table',
142 'containerId': 'chart7',
152 'columns': [0, 1, 2, 3, 4, 5]
156 function avg_bandwidth(arr) {
158 for (var i = 0; i < arr.length; i++) {
159 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
164 return ret/arr.length;
167 function sum_bytes_sent_as_bw(arr) {
169 for (var i = 0; i < arr.length; i++) {
170 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
175 function sum_bytes_sent_as_GB(arr) {
177 for (var i = 0; i < arr.length; i++) {
178 ret+=arr[i]/1024.0/1024.0/1024.0;
183 function fixDate2(unixDate) {
184 // not completely sure why we have to do this, as the data was in
185 // javascript Date() objects to start with. If we don't do it,
186 // then the horizontal axis will be blank.
187 return new Date(unixDate);
190 var format0dp = new google.visualization.NumberFormat({fractionDigits:0});
191 var format2dp = new google.visualization.NumberFormat({fractionDigits:2});
193 if (response.isError()) {
194 $( "#chart-site-agg" ).html("<div class='loading'>Error while fetching data.</div>");
198 if (response.getDataTable().getNumberOfRows() == 0) {
199 $( "#chart-site-agg" ).html("<div class='loading'>No data for this slice.</div>");
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>