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