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