blob: 8f4f45a398e5d2088618d3a84505f370c933e5ec [file] [log] [blame]
Scott Baker19244ec2014-04-28 23:30:04 -07001<div id="tabs-6">
Scott Baker7cc6c7f2014-04-29 11:30:08 -07002<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 Baker19244ec2014-04-28 23:30:04 -070010</div>
Scott Baker7cc6c7f2014-04-29 11:30:08 -070011<div id="cdn-node-table"></div>
12</div>
Scott Baker19244ec2014-04-28 23:30:04 -070013<script>
14
15function 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
25jQuery.fn.dataTableExt.oSort['domain-name-asc'] = function(a,b) {
26 return domain_name_sort(a,b);
27};
28
29jQuery.fn.dataTableExt.oSort['domain-name-desc'] = function(a,b) {
30 retuirn -domain_name_sort(a,b);
31};
32
33function updateCDNNodeData(data) {
Scott Baker7cc6c7f2014-04-29 11:30:08 -070034 $('#cdn-node-table').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="dynamic_cdn_nodes"></table>' );
Scott Baker19244ec2014-04-28 23:30:04 -070035 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 Bakerb214c2a2014-04-29 09:58:17 -070051 Mbps = parseInt(rows[row]['sum_computed_bytes_sent_div_elapsed'] * 8.0 / 1024.0 / 1024.0);
Scott Baker19244ec2014-04-28 23:30:04 -070052
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
74function updateCDNNodes() {
Scott Bakereaf52c92014-05-13 17:23:41 -070075 var contentProvider = $("#cdn-node-data-slicename").val();
76
77 var filterPart = ""
78 if ((contentProvider!="") && (contentProvider!="all")) {
79 filterPart = "&cp=" + contentProvider
80 }
81
82 var url= '/analytics/bigquery/?event=hpc_heartbeat&sum=@bytes_sent,@bytes_hit,@healthy,@elapsed&computed=@bytes_sent/@elapsed&groupBy=@hostname&cached=hpc&cachedGroupBy=@hostname' + filterPart;
83
Scott Baker19244ec2014-04-28 23:30:04 -070084 console.log(url);
Scott Bakereaf52c92014-05-13 17:23:41 -070085
Scott Baker19244ec2014-04-28 23:30:04 -070086 $.ajax({
87 url: url,
88 dataType : 'json',
89 type : 'GET',
90 success: function(newData)
91 {
92 updateCDNNodeData(newData);
93 }
94});
95 setTimeout(updateCDNNodes, 30000);
96}
97
Scott Bakereaf52c92014-05-13 17:23:41 -070098google.setOnLoadCallback(function () {
99 $('#cdn-node-data-slicename').change(function()
100 {
101 updateCDNNodes();
102 });
103
104 updateCDNNodes();
105});
106
107//setTimeout(updateCDNNodes, 5000);
Scott Baker19244ec2014-04-28 23:30:04 -0700108</script>