blob: bf7e37d45c55bb95bc520777786d15188f4c25b6 [file] [log] [blame]
Scott Baker0fd787d2014-05-13 17:03:47 -07001function getPageKind() {
Scott Baker61aefcf2014-04-25 15:21:18 -07002 var parentNodeTxt = $('#selectedMainNav').text();
Scott Baker771819b2014-03-19 22:10:17 -07003 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 Baker0fd787d2014-05-13 17:03:47 -07009 return parentNodeTxt;
10}
11
12function getObjectQuery() {
13 var selectedNodeTxt = $('#currentOriginalNode').text();
14 selectedNodeTxt = selectedNodeTxt.trim();
15 selectedNodeTxt = selectedNodeTxt.split(' ').join('');//selectedNodeTxt.replace(" ", "")
16 parentNodeTxt = getPageKind();
Scott Baker771819b2014-03-19 22:10:17 -070017
18 if (parentNodeTxt == "Slice") {
Scott Baker0fd787d2014-05-13 17:03:47 -070019 return "&slice=" + selectedNodeTxt;
Scott Baker771819b2014-03-19 22:10:17 -070020 } else if (parentNodeTxt == "Site") {
Scott Baker0fd787d2014-05-13 17:03:47 -070021 return "&site=" + selectedNodeTxt;
Scott Baker771819b2014-03-19 22:10:17 -070022 } else if (parentNodeTxt == "Node") {
Scott Baker0fd787d2014-05-13 17:03:47 -070023 return "&node=" + selectedNodeTxt;
Scott Baker771819b2014-03-19 22:10:17 -070024 } else {
Scott Baker0fd787d2014-05-13 17:03:47 -070025 return "";
Scott Baker771819b2014-03-19 22:10:17 -070026 }
27}
28
29
30function setPageStatInt(labelName, valueName, legend, units, value) {
Scott Baker8465c2b2014-03-27 09:11:14 -070031 $(labelName).text(legend).show();
32 $(valueName).text(Math.round(value)+units).show();
Scott Baker771819b2014-03-19 22:10:17 -070033}
34
35function setPageStatFloat(labelName, valueName, legend, units, value, dp) {
Scott Baker8465c2b2014-03-27 09:11:14 -070036 $(labelName).text(legend).show();
37 $(valueName).text(Number(value).toFixed(dp)+units).show();
Scott Baker771819b2014-03-19 22:10:17 -070038}
39
40// ----------------------------------------------------------------------------
41// node count and average cpu utilization
42
43function updatePageAnalyticsData(summaryData) {
Scott Baker8465c2b2014-03-27 09:11:14 -070044 window.pageAnalyticsUrl = summaryData["dataSourceUrl"];
Scott Baker771819b2014-03-19 22:10:17 -070045 lastRow = summaryData.rows.length-1;
Scott Baker8465c2b2014-03-27 09:11:14 -070046
Scott Bakerf2c26de2014-06-10 20:37:40 -070047 if (summaryData.msg) {
48 $("#minidashStatus").text(summaryData.msg).show();
49 } else {
50 $("#minidashStatus").text("").hide();
51 }
52
Scott Baker6c0e7842014-06-10 19:51:07 -070053 if (summaryData.rows.length <= 0) {
54 //console.log("no data received from page analytics ajax")
55 return;
56 }
57
Scott Bakerf2c26de2014-06-10 20:37:40 -070058 //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 Baker8465c2b2014-03-27 09:11:14 -070061
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 Baker771819b2014-03-19 22:10:17 -070065}
66
67function updatePageAnalytics() {
Scott Baker0fd787d2014-05-13 17:03:47 -070068 var url= '/analytics/bigquery/?avg=%cpu&count=%hostname&cached=default' + getObjectQuery();
Scott Baker771819b2014-03-19 22:10:17 -070069 $.ajax({
Scott Baker61aefcf2014-04-25 15:21:18 -070070 url: url,
Scott Baker771819b2014-03-19 22:10:17 -070071 dataType : 'json',
72 type : 'GET',
Scott Bakerb23dd1d2014-06-09 16:03:35 -070073 success: function(newData) {
Scott Baker771819b2014-03-19 22:10:17 -070074 updatePageAnalyticsData(newData);
Scott Bakerb23dd1d2014-06-09 16:03:35 -070075 setTimeout(updatePageAnalytics, 30000);
76 },
77 error: function() {
78 console.log("error retrieving statistics; retry in 5 seconds");
79 setTimeout(updatePageBandwidth, 5000);
Scott Baker771819b2014-03-19 22:10:17 -070080 }
81});
Scott Baker771819b2014-03-19 22:10:17 -070082}
83
Scott Baker771819b2014-03-19 22:10:17 -070084// ----------------------------------------------------------------------------
85// bandwidth
86
87function updatePageBandwidthData(summaryData) {
Scott Baker8465c2b2014-03-27 09:11:14 -070088 window.pageBandwidthUrl = summaryData["dataSourceUrl"];
Scott Baker771819b2014-03-19 22:10:17 -070089 lastRow = summaryData.rows.length-1;
Scott Baker6c0e7842014-06-10 19:51:07 -070090
91 if (summaryData.rows.length <= 0) {
92 //console.log("no data received from page bandwidth ajax")
93 return;
94 }
95
Scott Bakerf2c26de2014-06-10 20:37:40 -070096 //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 Baker8465c2b2014-03-27 09:11:14 -0700100 setPageStatFloat("#miniDashBandwidthLabel", "#miniDashBandwidth", "Bandwidth", " Gbps", summaryData.rows[lastRow]["sum_computed_bytes_sent_div_elapsed"]*8.0/1024/1024/1024,2);
Scott Baker771819b2014-03-19 22:10:17 -0700101}
102
103function updatePageBandwidth() {
Scott Baker0fd787d2014-05-13 17:03:47 -0700104 var url='/analytics/bigquery/?computed=%bytes_sent/%elapsed&cached=default' + getObjectQuery();
105
106 if (getPageKind()!="Slice") {
107 url = url + "&event=node_heartbeat";
108 }
Scott Baker61aefcf2014-04-25 15:21:18 -0700109
Scott Baker771819b2014-03-19 22:10:17 -0700110 $.ajax({
Scott Baker61aefcf2014-04-25 15:21:18 -0700111 url : url,
Scott Baker771819b2014-03-19 22:10:17 -0700112 dataType : 'json',
113 type : 'GET',
Scott Bakerb23dd1d2014-06-09 16:03:35 -0700114 success: function(newData) {
Scott Baker771819b2014-03-19 22:10:17 -0700115 updatePageBandwidthData(newData);
Scott Bakerb23dd1d2014-06-09 16:03:35 -0700116 setTimeout(updatePageBandwidth, 30000);
117 },
118 error: function() {
119 console.log("error retrieving statistics; retry in 5 seconds")
120 setTimeout(updatePageBandwidth, 5000);
Scott Baker771819b2014-03-19 22:10:17 -0700121 }
122});
Scott Baker771819b2014-03-19 22:10:17 -0700123}
124
Scott Bakerca2e22d2014-05-23 18:26:06 -0700125$( document ).ready(function() {
126 updatePageAnalytics();
127 updatePageBandwidth();
128});
Scott Baker771819b2014-03-19 22:10:17 -0700129