Scott Baker | 19244ec | 2014-04-28 23:30:04 -0700 | [diff] [blame] | 1 | <div id="tabs-6"> |
| 2 | </div> |
| 3 | |
| 4 | <script> |
| 5 | |
| 6 | function domain_name_sort(a,b) { |
| 7 | parts_a = a.split("."); |
| 8 | parts_b = b.split("."); |
| 9 | parts_a = parts_a.reverse(); |
| 10 | parts_b = parts_b.reverse(); |
| 11 | a = parts_a.join("."); |
| 12 | b = parts_b.join("."); |
| 13 | return ((a < b) ? -1 : ((a > b) ? 1 : 0)); |
| 14 | } |
| 15 | |
| 16 | jQuery.fn.dataTableExt.oSort['domain-name-asc'] = function(a,b) { |
| 17 | return domain_name_sort(a,b); |
| 18 | }; |
| 19 | |
| 20 | jQuery.fn.dataTableExt.oSort['domain-name-desc'] = function(a,b) { |
| 21 | retuirn -domain_name_sort(a,b); |
| 22 | }; |
| 23 | |
| 24 | function updateCDNNodeData(data) { |
| 25 | $('#tabs-6').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="dynamic_cdn_nodes"></table>' ); |
| 26 | var actualEntries = []; |
| 27 | |
| 28 | var rows = data.rows; |
| 29 | for (row in rows) { |
| 30 | hostname = rows[row]['hostname']; |
| 31 | bytes_sent = rows[row]['sum_bytes_sent']; |
| 32 | bytes_hit = rows[row]['sum_bytes_hit']; |
| 33 | elapsed = rows[row]['sum_elapsed']; |
| 34 | healthy = rows[row]['sum_healthy']; |
| 35 | |
| 36 | if (bytes_sent > 0) { |
| 37 | hit_ratio = parseInt( bytes_hit * 100.0 / bytes_sent ); |
| 38 | } else { |
| 39 | hit_ratio = 0; |
| 40 | } |
| 41 | |
Scott Baker | b214c2a | 2014-04-29 09:58:17 -0700 | [diff] [blame^] | 42 | Mbps = parseInt(rows[row]['sum_computed_bytes_sent_div_elapsed'] * 8.0 / 1024.0 / 1024.0); |
Scott Baker | 19244ec | 2014-04-28 23:30:04 -0700 | [diff] [blame] | 43 | |
| 44 | if (healthy>0) { |
| 45 | healthyStr = "ok"; |
| 46 | } else { |
| 47 | healthyStr = "bad"; |
| 48 | } |
| 49 | |
| 50 | actualEntries.push([hostname, healthyStr, Mbps, hit_ratio]); |
| 51 | } |
| 52 | oTable = $('#dynamic_cdn_nodes').dataTable( { |
| 53 | "bJQueryUI": true, |
| 54 | "aaData": actualEntries, |
| 55 | "bStateSave": true, |
| 56 | "aoColumns": [ |
| 57 | { "sTitle": "Hostname", sType: "domain-name" }, |
| 58 | { "sTitle": "Healthy" }, |
| 59 | { "sTitle": "Mbps" , sClass: "alignCenter"}, |
| 60 | { "sTitle": "Hit Ratio" , sClass: "alignCenter"}, |
| 61 | ], |
| 62 | } ); |
| 63 | } |
| 64 | |
| 65 | function updateCDNNodes() { |
Scott Baker | b214c2a | 2014-04-29 09:58:17 -0700 | [diff] [blame^] | 66 | var url= '/analytics/bigquery/?event=hpc_heartbeat&sum=@bytes_sent,@bytes_hit,@healthy,@elapsed&computed=@bytes_sent/@elapsed&groupBy=@hostname&cached=1&cachedGroupBy=@hostname'; |
Scott Baker | 19244ec | 2014-04-28 23:30:04 -0700 | [diff] [blame] | 67 | console.log(url); |
| 68 | $.ajax({ |
| 69 | url: url, |
| 70 | dataType : 'json', |
| 71 | type : 'GET', |
| 72 | success: function(newData) |
| 73 | { |
| 74 | updateCDNNodeData(newData); |
| 75 | } |
| 76 | }); |
| 77 | setTimeout(updateCDNNodes, 30000); |
| 78 | } |
| 79 | |
| 80 | setTimeout(updateCDNNodes, 5000); |
| 81 | </script> |