Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 1 | google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']}); |
| 2 | |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 3 | function renderChart(origQuery, yColumn, xColumn, title, aggFunc) { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 4 | $('#graph').empty(); |
| 5 | $('#chartsModal').modal('show'); |
| 6 | $('.modal-body').scrollTop(0) |
| 7 | |
| 8 | var queryString = encodeURIComponent(origQuery); |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 9 | var serverPart = "http://cloud-scrutiny.appspot.com/command?table=demoevents&action=send_query&force=ColumnChart&q="; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 10 | var dataSourceUrl = serverPart + queryString; |
| 11 | |
| 12 | //var dataSourceUrl = "http://node36.princeton.vicci.org:8000/analytics/bigquery/?avg=%25cpu&count=%25hostname&format=raw"; |
| 13 | |
| 14 | var query = new google.visualization.Query(dataSourceUrl) |
| 15 | query && query.abort(); |
| 16 | console.log("query.send") |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 17 | query.send(function(response) {handleResponse_psg(response, yColumn, xColumn, title, aggFunc);}); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 18 | console.log("query.sent") |
| 19 | } |
| 20 | |
| 21 | // NOTE: appended _psg to showLine() and handleResponse() to prevent conflict |
| 22 | // with Sapan's analytics page. |
| 23 | |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 24 | function agg_bandwidth(arr) { |
| 25 | var ret = 0; |
| 26 | for (var i = 0; i < arr.length; i++) { |
| 27 | ret+=arr[i]*8.0/1024.0/1024.0/1024.0; |
| 28 | } |
| 29 | return ret; |
| 30 | } |
| 31 | |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 32 | function showLine_psg(dt, title) { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 33 | console.log("showline") |
| 34 | var lineChart = new google.visualization.ChartWrapper({ |
| 35 | 'chartType': 'LineChart', |
| 36 | 'containerId': 'graph', |
| 37 | 'options': { |
| 38 | 'width': 520, |
| 39 | 'height': 300, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 40 | 'title': title, |
| 41 | 'pages': true, |
| 42 | 'numRows': 9, |
| 43 | 'backgroundColor': 'transparent', |
| 44 | 'titleTextStyle': {"color": "white"}, |
| 45 | 'legend': 'none', |
| 46 | // 'legend': {"textStyle": {"color": "white"}}, |
| 47 | 'hAxis': {"baselineColor": "white", |
| 48 | "textStyle": {"color": "white"}}, |
| 49 | 'vAxis': {"baselineColor": "white", |
| 50 | "textStyle": {"color": "white"}}, |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 51 | }, |
| 52 | 'view': {'columns': [0, 1]} |
| 53 | }); |
| 54 | lineChart.setDataTable(dt); |
| 55 | lineChart.draw(); |
| 56 | } |
| 57 | |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 58 | function fixDate(unixDate) { |
| 59 | return new Date(unixDate*1000); |
| 60 | } |
| 61 | |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 62 | function handleResponse_psg(response, yColumn, xColumn, title, aggFunc) { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 63 | console.log("handleResponse") |
| 64 | |
| 65 | var supportedClasses = { |
| 66 | 'Table':google.visualization.Table, |
| 67 | 'LineChart':google.visualization.LineChart, |
| 68 | 'ScatterChart':google.visualization.ScatterChart, |
| 69 | 'ColumnChart':google.visualization.ColumnChart, |
| 70 | 'GeoChart':google.visualization.GeoChart, |
| 71 | 'PieChart':google.visualization.PieChart, |
| 72 | 'Histogram':google.visualization.Histogram}; |
| 73 | |
| 74 | var proxy = new google.visualization.ChartWrapper({ |
| 75 | 'chartType': 'Table', |
| 76 | 'containerId': 'graph_work', |
| 77 | 'options': { |
| 78 | 'width': 800, |
| 79 | 'height': 300, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 80 | pageSize:5, |
| 81 | page:'enable', |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 82 | 'legend': 'none', |
| 83 | 'title': 'Nodes' |
| 84 | }, |
| 85 | 'view': {'columns': [0,1]} |
| 86 | }); |
| 87 | |
| 88 | google.visualization.events.addListener(proxy, 'ready', function () { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 89 | var dt = proxy.getDataTable(); |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 90 | var groupedData1 = google.visualization.data.group(dt, [{ |
| 91 | column: yColumn, |
| 92 | type: 'datetime', |
| 93 | modifier: fixDate, |
| 94 | }], |
| 95 | [{ |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 96 | column: xColumn, |
| 97 | type: 'number', |
| 98 | label: dt.getColumnLabel(xColumn), |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 99 | aggregation: aggFunc}]); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 100 | |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 101 | showLine_psg(groupedData1, title); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 102 | |
| 103 | console.log(xColumn); |
| 104 | }); |
| 105 | |
| 106 | console.log(response.getReasons()); |
| 107 | console.log(response.getDataTable()); |
| 108 | console.log(response.getDetailedMessage()); |
| 109 | console.log(response.getMessage()); |
| 110 | |
| 111 | proxy.setDataTable(response.getDataTable()); |
| 112 | |
| 113 | proxy.draw(); |
| 114 | } |
| 115 | |
| 116 | $('.nodesLabel, .nodesValue').click(function() { |
| 117 | var jsonData = window.pageAnalyticsData; |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 118 | renderChart(jsonData.query, 0, 2, "Node Count", google.visualization.data.sum); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 119 | //renderChartJson(jsonData, "MinuteTime", "count_hostname", "Node Count"); |
| 120 | }); |
| 121 | |
| 122 | $('.cpuLabel, .cpuValue').click(function() { |
| 123 | var jsonData = window.pageAnalyticsData; |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 124 | renderChart(jsonData.query, 0, 1, "Average CPU", google.visualization.data.sum); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 125 | }); |
| 126 | $('.bandwidthLabel, .bandwidthValue').click(function() { |
| 127 | var jsonData = window.pageBandData; |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame^] | 128 | renderChart(jsonData.query, 0, 1, "Total Bandwidth", agg_bandwidth); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 129 | }); |