Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 1 | function getObjectAndEventQuery() { |
| 2 | var selectedNodeTxt = $('#currentOriginalNode').text(); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 3 | selectedNodeTxt = selectedNodeTxt.trim(); |
| 4 | selectedNodeTxt = selectedNodeTxt.split(' ').join('');//selectedNodeTxt.replace(" ", "") |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 5 | var parentNodeTxt = $('#selectedMainNav').text(); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 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") { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 14 | return "&event=libvirt_heartbeat&slice=" + selectedNodeTxt; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 15 | } else if (parentNodeTxt == "Site") { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 16 | return "&event=node_heartbeat&site=" + selectedNodeTxt; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 17 | } else if (parentNodeTxt == "Node") { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 18 | return "&event=node_heartbeat&node=" + selectedNodeTxt; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 19 | } else { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 20 | return "&event=node_heartbeat"; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 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() { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 51 | var url= '/analytics/bigquery/?avg=%cpu&count=%hostname&cached=1' + getObjectAndEventQuery(); |
| 52 | console.log(url); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 53 | $.ajax({ |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 54 | url: url, |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 55 | dataType : 'json', |
| 56 | type : 'GET', |
| 57 | success: function(newData) |
| 58 | { |
| 59 | updatePageAnalyticsData(newData); |
| 60 | } |
| 61 | }); |
| 62 | setTimeout(updatePageAnalytics, 30000); |
| 63 | } |
| 64 | |
| 65 | setTimeout(updatePageAnalytics, 5000); |
| 66 | |
| 67 | // ---------------------------------------------------------------------------- |
| 68 | // bandwidth |
| 69 | |
| 70 | function updatePageBandwidthData(summaryData) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 71 | window.pageBandwidthUrl = summaryData["dataSourceUrl"]; |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 72 | lastRow = summaryData.rows.length-1; |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 73 | setPageStatFloat(".bandwidthLabel", ".bandwidthValue", "Bandwidth", " Gbps", summaryData.rows[lastRow]["sum_computed_bytes_sent_div_elapsed"]*8.0/1024/1024/1024,2); |
| 74 | 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] | 75 | } |
| 76 | |
| 77 | function updatePageBandwidth() { |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 78 | var url='/analytics/bigquery/?computed=%bytes_sent/%elapsed&cached=1' + getObjectAndEventQuery(); |
| 79 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 80 | $.ajax({ |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 81 | url : url, |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 82 | dataType : 'json', |
| 83 | type : 'GET', |
| 84 | success: function(newData) |
| 85 | { |
| 86 | updatePageBandwidthData(newData); |
| 87 | } |
| 88 | }); |
| 89 | setTimeout(updatePageBandwidth, 30000); |
| 90 | } |
| 91 | |
| 92 | setTimeout(updatePageBandwidth, 5000); |
| 93 | |