Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 1 | function controller_status(data_source){ |
| 2 | /* var data = [{name:'onos9vpc', onos: 1, cassandra: 1}, |
| 3 | {name:'onos10vpc', onos: 0, cassandra: 1}, |
| 4 | {name:'onos11vpc', onos: 1, cassandra: 1}, |
| 5 | {name:'onos12vpc', onos: 0, cassandra: 1}] */ |
| 6 | |
| 7 | var barWidth = 100; |
| 8 | var width = (barWidth + 10) * 4 |
| 9 | var height = 50; |
| 10 | |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 11 | var Servers = d3.select("#servers"). |
| 12 | append("svg:svg"). |
| 13 | attr("width", 800). |
| 14 | attr("height", 30); |
| 15 | |
| 16 | var ContStatus = d3.select("#onos-status"). |
| 17 | append("svg:svg"). |
| 18 | attr("width", 800). |
| 19 | attr("height", 50); |
| 20 | |
| 21 | var CassandraStatus = d3.select("#cassandra-status"). |
| 22 | append("svg:svg"). |
| 23 | attr("width", 800). |
| 24 | attr("height", 50); |
| 25 | |
| 26 | d3.json(data_source, draw); |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 27 | setInterval(function() { |
| 28 | $.ajax({ |
| 29 | url: data_source, |
| 30 | success: function(json) { |
| 31 | draw(json) |
| 32 | }, |
| 33 | dataType: "json" |
| 34 | }); |
| 35 | }, 5000); |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 36 | |
| 37 | function draw(json){ |
| 38 | // var data = json.data; |
| 39 | var data = json; |
| 40 | var server = Servers.selectAll("text").data(data); |
| 41 | var controller_rect = ContStatus.selectAll("rect").data(data); |
| 42 | var controller_text = ContStatus.selectAll("text").data(data); |
| 43 | var cassandra_rect = CassandraStatus.selectAll("rect").data(data); |
| 44 | var cassandra_text = CassandraStatus.selectAll("text").data(data); |
| 45 | |
| 46 | var x = d3.scale.linear().domain([0, data.length]).range([0, width]); |
| 47 | var y = d3.scale.linear().domain([0, d3.max(data, function(datum) { return datum.onos; })]).rangeRound([0, height]); |
| 48 | var y2 = d3.scale.linear().domain([0, d3.max(data, function(datum) { return datum.cassandra; })]).rangeRound([0, height]); |
| 49 | |
| 50 | console.log(data) |
| 51 | server. |
| 52 | enter(). |
| 53 | append("svg:text"). |
| 54 | attr("x", function(datum, index) { return x(index); }). |
| 55 | attr("y", function(datum) { return 20; }). |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 56 | attr("fill", function(datum, index) { |
| 57 | if (index == 0){ |
| 58 | return "red" |
| 59 | }else if (index == 1){ |
| 60 | return "blue" |
| 61 | }else if (index == 2){ |
| 62 | return "green" |
| 63 | }else if (index == 3){ |
| 64 | return "orange" |
| 65 | }else{ |
| 66 | return "black" |
| 67 | } |
| 68 | }). |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 69 | text(function(datum) { return datum.name; }); |
| 70 | |
| 71 | controller_rect. |
| 72 | enter(). |
| 73 | append("svg:rect"). |
| 74 | attr("x", function(datum, index) { return x(index); }). |
| 75 | attr("y", function(datum) { return height - y(datum.onos); }). |
| 76 | attr("height", function(datum) { return y(datum.onos); }). |
| 77 | attr("width", barWidth). |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 78 | attr("fill", function(datum, index) { |
| 79 | if (index == 0){ |
| 80 | return "red" |
| 81 | }else if (index == 1){ |
| 82 | return "blue" |
| 83 | }else if (index == 2){ |
| 84 | return "green" |
| 85 | }else if (index == 3){ |
| 86 | return "orange" |
| 87 | }else{ |
| 88 | return "black" |
| 89 | } |
| 90 | }); |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 91 | |
| 92 | controller_text. |
| 93 | enter(). |
| 94 | append("svg:text"). |
| 95 | text(function(){return "ONOS"}). |
| 96 | attr("x", function(datum, index) { return x(index)+10; }). |
| 97 | attr("y", function(datum) { return 30 ; }). |
| 98 | attr("height", function(datum) { return y(datum.onos); }). |
| 99 | attr("width", barWidth). |
| 100 | attr('fill', 'white'); |
| 101 | |
| 102 | cassandra_rect. |
| 103 | enter(). |
| 104 | append("svg:rect"). |
| 105 | attr("x", function(datum, index) { return x(index); }). |
| 106 | attr("y", function(datum) { return height - y2(datum.cassandra); }). |
| 107 | attr("height", function(datum) { return y2(datum.cassandra); }). |
| 108 | attr("width", barWidth). |
| 109 | attr("fill", "#aa0000"); |
| 110 | |
| 111 | cassandra_text. |
| 112 | enter(). |
| 113 | append("svg:text"). |
| 114 | text(function(){return "Cassandra"}). |
| 115 | attr("x", function(datum, index) { return x(index); }). |
| 116 | attr("y", function(datum) { return 30 ; }). |
| 117 | attr("height", function(datum) { return y(datum.onos); }). |
| 118 | attr("width", barWidth). |
| 119 | attr('fill', 'white'); |
| 120 | |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 121 | |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 122 | controller_rect. |
| 123 | attr("x", function(datum, index) { return x(index); }). |
| 124 | attr("y", function(datum) { return height - y(datum.onos); }). |
| 125 | attr("height", function(datum) { return y(datum.onos); }). |
| 126 | attr("width", barWidth). |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 127 | attr("fill", function(datum, index) { |
| 128 | if (index == 0){ |
| 129 | return "red" |
| 130 | }else if (index == 1){ |
| 131 | return "blue" |
| 132 | }else if (index == 2){ |
| 133 | return "green" |
| 134 | }else if (index == 3){ |
| 135 | return "orange" |
| 136 | }else{ |
| 137 | return "black" |
| 138 | } |
| 139 | }); |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 140 | |
| 141 | controller_text. |
| 142 | text(function(){return "ONOS"}). |
| 143 | attr("x", function(datum, index) { return x(index)+10; }). |
| 144 | attr("y", function(datum) { return 30 ; }). |
| 145 | attr("height", function(datum) { return y(datum.onos); }). |
| 146 | attr("width", barWidth). |
| 147 | attr('fill', 'white'); |
| 148 | |
| 149 | cassandra_rect. |
| 150 | attr("x", function(datum, index) { return x(index); }). |
| 151 | attr("y", function(datum) { return height - y2(datum.cassandra); }). |
| 152 | attr("height", function(datum) { return y2(datum.cassandra); }). |
| 153 | attr("width", barWidth). |
| 154 | attr("fill", "#aa0000"); |
| 155 | |
| 156 | cassandra_text. |
| 157 | text(function(){return "Cassandra"}). |
| 158 | attr("x", function(datum, index) { return x(index); }). |
| 159 | attr("y", function(datum) { return 30 ; }). |
| 160 | attr("height", function(datum) { return y(datum.cassandra); }). |
| 161 | attr("width", barWidth). |
| 162 | attr('fill', 'white'); |
| 163 | |
| 164 | |
| 165 | server.exit().remove(); |
| 166 | controller_rect.exit().remove(); |
| 167 | controller_text.exit().remove(); |
| 168 | cassandra_rect.exit().remove(); |
| 169 | cassandra_text.exit().remove(); |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 170 | |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 171 | } |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 172 | /* |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 173 | $("#more").click( function() { |
| 174 | $.ajax({ |
| 175 | url: 'http://gui.onlab.us:8080/controller_status1', |
| 176 | success: function(json) { |
| 177 | draw(json); |
| 178 | }, |
| 179 | dataType: "json" |
| 180 | }); |
| 181 | }); |
| 182 | $("#less").click( function() { |
| 183 | $.ajax({ |
| 184 | url: 'http://gui.onlab.us:8080/controller_status2', |
| 185 | success: function(json) { |
| 186 | draw(json); |
| 187 | }, |
| 188 | dataType: "json" |
| 189 | }); |
| 190 | }); |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 191 | */ |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 192 | } |
| 193 | |