blob: 07abce006ca587b05b3749a0a3a520daa9d6e541 [file] [log] [blame]
Scott Baker19244ec2014-04-28 23:30:04 -07001<div id="tabs-6">
2</div>
3
4<script>
5
6function 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
16jQuery.fn.dataTableExt.oSort['domain-name-asc'] = function(a,b) {
17 return domain_name_sort(a,b);
18};
19
20jQuery.fn.dataTableExt.oSort['domain-name-desc'] = function(a,b) {
21 retuirn -domain_name_sort(a,b);
22};
23
24function 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
42 if (elapsed > 0) {
43 Mbps = parseInt( (bytes_sent * 8.0 / 1024.0 / 1024.0 ) / elapsed );
44 } else {
45 Mbps = 0;
46 }
47
48 if (healthy>0) {
49 healthyStr = "ok";
50 } else {
51 healthyStr = "bad";
52 }
53
54 actualEntries.push([hostname, healthyStr, Mbps, hit_ratio]);
55 }
56 oTable = $('#dynamic_cdn_nodes').dataTable( {
57 "bJQueryUI": true,
58 "aaData": actualEntries,
59 "bStateSave": true,
60 "aoColumns": [
61 { "sTitle": "Hostname", sType: "domain-name" },
62 { "sTitle": "Healthy" },
63 { "sTitle": "Mbps" , sClass: "alignCenter"},
64 { "sTitle": "Hit Ratio" , sClass: "alignCenter"},
65 ],
66 } );
67}
68
69function updateCDNNodes() {
70 var url= '/analytics/bigquery/?event=hpc_heartbeat&sum=@bytes_sent,@bytes_hit,@healthy,@elapsed&groupBy=@hostname&cached=1&cachedGroupBy=@hostname';
71 console.log(url);
72 $.ajax({
73 url: url,
74 dataType : 'json',
75 type : 'GET',
76 success: function(newData)
77 {
78 updateCDNNodeData(newData);
79 }
80});
81 setTimeout(updateCDNNodes, 30000);
82}
83
84setTimeout(updateCDNNodes, 5000);
85</script>