blob: d93667da71a499dbd2b28f9029059c804c230f75 [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 $.ajax({
85 url: url,
86 dataType : 'json',
87 type : 'GET',
88 success: function(newData)
89 {
90 updateCDNNodeData(newData);
91 }
92});
93 setTimeout(updateCDNNodes, 30000);
94}
95
Scott Bakereaf52c92014-05-13 17:23:41 -070096google.setOnLoadCallback(function () {
97 $('#cdn-node-data-slicename').change(function()
98 {
99 updateCDNNodes();
100 });
101
102 updateCDNNodes();
103});
104
105//setTimeout(updateCDNNodes, 5000);
Scott Baker19244ec2014-04-28 23:30:04 -0700106</script>