Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 1 | function getPageKind() { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 2 | var parentNodeTxt = $('#selectedMainNav').text(); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 3 | parentNodeTxt = parentNodeTxt.replace("/\n",""); |
| 4 | parentNodeTxt = parentNodeTxt.replace("ยป",""); |
| 5 | parentNodeTxt = parentNodeTxt.trim(); |
| 6 | if (parentNodeTxt.length > 0 && parentNodeTxt.charAt(parentNodeTxt.length-1)=='s') { |
| 7 | parentNodeTxt = parentNodeTxt.substring(0, parentNodeTxt.length-1); |
| 8 | } |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 9 | return parentNodeTxt; |
| 10 | } |
| 11 | |
| 12 | function getObjectQuery() { |
| 13 | var selectedNodeTxt = $('#currentOriginalNode').text(); |
| 14 | selectedNodeTxt = selectedNodeTxt.trim(); |
| 15 | selectedNodeTxt = selectedNodeTxt.split(' ').join('');//selectedNodeTxt.replace(" ", "") |
| 16 | parentNodeTxt = getPageKind(); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 17 | |
| 18 | if (parentNodeTxt == "Slice") { |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 19 | return "&slice=" + selectedNodeTxt; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 20 | } else if (parentNodeTxt == "Site") { |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 21 | return "&site=" + selectedNodeTxt; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 22 | } else if (parentNodeTxt == "Node") { |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 23 | return "&node=" + selectedNodeTxt; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 24 | } else { |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 25 | return ""; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
| 29 | |
| 30 | function setPageStatInt(labelName, valueName, legend, units, value) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 31 | $(labelName).text(legend).show(); |
| 32 | $(valueName).text(Math.round(value)+units).show(); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | function setPageStatFloat(labelName, valueName, legend, units, value, dp) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 36 | $(labelName).text(legend).show(); |
| 37 | $(valueName).text(Number(value).toFixed(dp)+units).show(); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // ---------------------------------------------------------------------------- |
| 41 | // node count and average cpu utilization |
| 42 | |
| 43 | function updatePageAnalyticsData(summaryData) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 44 | window.pageAnalyticsUrl = summaryData["dataSourceUrl"]; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 45 | lastRow = summaryData.rows.length-1; |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 46 | |
| 47 | setPageStatInt(".nodesLabel", ".nodesValue", "Node Count", "", summaryData.rows[lastRow]["count_hostname"]); |
| 48 | setPageStatInt(".cpuLabel", ".cpuValue", "Avg Load", "%", summaryData.rows[lastRow]["avg_cpu"]); |
| 49 | |
| 50 | //New miniDashboard |
| 51 | setPageStatInt("#miniDashNodeCountLabel", "#miniDashNodeCount", "Node Count", "", summaryData.rows[lastRow]["count_hostname"]); |
| 52 | setPageStatInt("#miniDashAvgLoadLabel", "#miniDashAvgLoad", "Avg Load", "%", summaryData.rows[lastRow]["avg_cpu"]); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | function updatePageAnalytics() { |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 56 | var url= '/analytics/bigquery/?avg=%cpu&count=%hostname&cached=default' + getObjectQuery(); |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 57 | console.log(url); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 58 | $.ajax({ |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 59 | url: url, |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 60 | dataType : 'json', |
| 61 | type : 'GET', |
| 62 | success: function(newData) |
| 63 | { |
| 64 | updatePageAnalyticsData(newData); |
| 65 | } |
| 66 | }); |
| 67 | setTimeout(updatePageAnalytics, 30000); |
| 68 | } |
| 69 | |
| 70 | setTimeout(updatePageAnalytics, 5000); |
| 71 | |
| 72 | // ---------------------------------------------------------------------------- |
| 73 | // bandwidth |
| 74 | |
| 75 | function updatePageBandwidthData(summaryData) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 76 | window.pageBandwidthUrl = summaryData["dataSourceUrl"]; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 77 | lastRow = summaryData.rows.length-1; |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 78 | setPageStatFloat(".bandwidthLabel", ".bandwidthValue", "Bandwidth", " Gbps", summaryData.rows[lastRow]["sum_computed_bytes_sent_div_elapsed"]*8.0/1024/1024/1024,2); |
| 79 | setPageStatFloat("#miniDashBandwidthLabel", "#miniDashBandwidth", "Bandwidth", " Gbps", summaryData.rows[lastRow]["sum_computed_bytes_sent_div_elapsed"]*8.0/1024/1024/1024,2); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | function updatePageBandwidth() { |
Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 83 | var url='/analytics/bigquery/?computed=%bytes_sent/%elapsed&cached=default' + getObjectQuery(); |
| 84 | |
| 85 | if (getPageKind()!="Slice") { |
| 86 | url = url + "&event=node_heartbeat"; |
| 87 | } |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 88 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 89 | $.ajax({ |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 90 | url : url, |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 91 | dataType : 'json', |
| 92 | type : 'GET', |
| 93 | success: function(newData) |
| 94 | { |
| 95 | updatePageBandwidthData(newData); |
| 96 | } |
| 97 | }); |
| 98 | setTimeout(updatePageBandwidth, 30000); |
| 99 | } |
| 100 | |
| 101 | setTimeout(updatePageBandwidth, 5000); |
| 102 | |