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