| 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 | |
| Scott Baker | 6c0e784 | 2014-06-10 19:51:07 -0700 | [diff] [blame^] | 47 | if (summaryData.rows.length <= 0) { |
| 48 | //console.log("no data received from page analytics ajax") |
| 49 | return; |
| 50 | } |
| 51 | |
| Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 52 | setPageStatInt(".nodesLabel", ".nodesValue", "Node Count", "", summaryData.rows[lastRow]["count_hostname"]); |
| 53 | setPageStatInt(".cpuLabel", ".cpuValue", "Avg Load", "%", summaryData.rows[lastRow]["avg_cpu"]); |
| 54 | |
| 55 | //New miniDashboard |
| 56 | setPageStatInt("#miniDashNodeCountLabel", "#miniDashNodeCount", "Node Count", "", summaryData.rows[lastRow]["count_hostname"]); |
| 57 | setPageStatInt("#miniDashAvgLoadLabel", "#miniDashAvgLoad", "Avg Load", "%", summaryData.rows[lastRow]["avg_cpu"]); |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | function updatePageAnalytics() { |
| Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 61 | var url= '/analytics/bigquery/?avg=%cpu&count=%hostname&cached=default' + getObjectQuery(); |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 62 | $.ajax({ |
| Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 63 | url: url, |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 64 | dataType : 'json', |
| 65 | type : 'GET', |
| Scott Baker | b23dd1d | 2014-06-09 16:03:35 -0700 | [diff] [blame] | 66 | success: function(newData) { |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 67 | updatePageAnalyticsData(newData); |
| Scott Baker | b23dd1d | 2014-06-09 16:03:35 -0700 | [diff] [blame] | 68 | setTimeout(updatePageAnalytics, 30000); |
| 69 | }, |
| 70 | error: function() { |
| 71 | console.log("error retrieving statistics; retry in 5 seconds"); |
| 72 | setTimeout(updatePageBandwidth, 5000); |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 73 | } |
| 74 | }); |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 77 | // ---------------------------------------------------------------------------- |
| 78 | // bandwidth |
| 79 | |
| 80 | function updatePageBandwidthData(summaryData) { |
| Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 81 | window.pageBandwidthUrl = summaryData["dataSourceUrl"]; |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 82 | lastRow = summaryData.rows.length-1; |
| Scott Baker | 6c0e784 | 2014-06-10 19:51:07 -0700 | [diff] [blame^] | 83 | |
| 84 | if (summaryData.rows.length <= 0) { |
| 85 | //console.log("no data received from page bandwidth ajax") |
| 86 | return; |
| 87 | } |
| 88 | |
| Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 89 | setPageStatFloat(".bandwidthLabel", ".bandwidthValue", "Bandwidth", " Gbps", summaryData.rows[lastRow]["sum_computed_bytes_sent_div_elapsed"]*8.0/1024/1024/1024,2); |
| 90 | 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] | 91 | } |
| 92 | |
| 93 | function updatePageBandwidth() { |
| Scott Baker | 0fd787d | 2014-05-13 17:03:47 -0700 | [diff] [blame] | 94 | var url='/analytics/bigquery/?computed=%bytes_sent/%elapsed&cached=default' + getObjectQuery(); |
| 95 | |
| 96 | if (getPageKind()!="Slice") { |
| 97 | url = url + "&event=node_heartbeat"; |
| 98 | } |
| Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 99 | |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 100 | $.ajax({ |
| Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 101 | url : url, |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 102 | dataType : 'json', |
| 103 | type : 'GET', |
| Scott Baker | b23dd1d | 2014-06-09 16:03:35 -0700 | [diff] [blame] | 104 | success: function(newData) { |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 105 | updatePageBandwidthData(newData); |
| Scott Baker | b23dd1d | 2014-06-09 16:03:35 -0700 | [diff] [blame] | 106 | setTimeout(updatePageBandwidth, 30000); |
| 107 | }, |
| 108 | error: function() { |
| 109 | console.log("error retrieving statistics; retry in 5 seconds") |
| 110 | setTimeout(updatePageBandwidth, 5000); |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 111 | } |
| 112 | }); |
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| Scott Baker | ca2e22d | 2014-05-23 18:26:06 -0700 | [diff] [blame] | 115 | $( document ).ready(function() { |
| 116 | updatePageAnalytics(); |
| 117 | updatePageBandwidth(); |
| 118 | });
|
| Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 119 | |