Skip to content

Commit

Permalink
change groups code
Browse files Browse the repository at this point in the history
  • Loading branch information
charsyam committed Jun 30, 2013
1 parent 8f41144 commit a814d68
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 34 deletions.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"name": "redis-2",
"type": "redis",
"nodes": [
{ "name": "server3", "host": "127.0.0.1", "port": 3001 },
{ "name": "server4", "host": "127.0.0.1", "port": 3002 }
{ "name": "server3", "host": "127.0.0.1", "port": 3003 },
{ "name": "server4", "host": "127.0.0.1", "port": 3004 }
]
}
]
Expand Down
5 changes: 2 additions & 3 deletions redisstat.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ http.createServer(app).listen(app.get('port'), function(){

var storage = new Storage();
require('./routes/getdata').add_routes(app, storage);
require('./routes/index').add_routes(app, storage);
require('./routes/groups').add_routes(app, storage);

var self = this;
self.request_count = 0;
Expand Down Expand Up @@ -76,9 +78,6 @@ for (var i in config.clusters) {
}
}

require('./routes/index').add_routes(app, self.clusters);
require('./routes/groups').add_routes(app, self.clusters);

setInterval(function() {
if (self.check == false) {
self.check = true;
Expand Down
8 changes: 5 additions & 3 deletions routes/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* GET home page.
*/

module.exports.add_routes = function(app, clusters) {
module.exports.add_routes = function(app, storage) {
app.get('/groups', function(req, res) {
res.render('groups', { title: 'Redis-Stat-Groups',
clusters: clusters});
storage.report_all(function(err, data) {
res.render('groups', { title: 'Redis-Stat-Groups',
clusters: data});
});
});
};
11 changes: 6 additions & 5 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* GET home page.
*/

module.exports.add_routes = function(app, clusters) {
module.exports.add_routes = function(app, storage) {
app.get('/', function(req, res) {
res.render('index', { title: 'Redis-Stat',
group: req.query['group'],
clusters: clusters});
storage.report_all(function(err, data) {
res.render('index', { title: 'Redis-Stat',
group: req.query['group'],
clusters: data});
});
});
};

10 changes: 4 additions & 6 deletions views/groups.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ function update(cluster, cluster_name) {
<h2><span id="title_name"><%= title %></span></h2>
</div>
<%
var cluster = clusters.clusters;
for (var idx in cluster) {
var info = cluster[idx];
for (var idx in clusters.clusters) {
var name = idx;
var info = clusters.clusters[idx];
%>
<% include partial/groups %>
<%
}
%>
<% } %>
<script>self.refresh()</script>
</body>
</html>
16 changes: 10 additions & 6 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,21 @@ function update(service, currentTimeMilliseconds, cluster_size) {
if (group != '') {
console.log("Not ''");
}
for (var idx in clusters.nodes) {
var server = clusters.nodes[idx];
console.log(group + " " + server.cluster_name);
for (var idx in clusters.clusters) {
console.log(idx);
var nodes = clusters.clusters[idx].nodes;
console.log(nodes);
for (var nidx in nodes) {
var server = nodes[nidx];
console.log(nidx+ " " + server.cluster_name);
if (one == true && group != server.cluster_name) {
continue;
}
%>
<% include partial/display %>
<%
}
%>
<% } %>
<% } %>
</div>
</div>
<script>self.refresh()</script>
Expand Down
25 changes: 16 additions & 9 deletions views/partial/groups.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<div class="alert">
<span class="label label-inverse"><%= info.name %></span>
<span class="label label-warning"><a href='/?group=<%= info.name %>'>View</a></span>
<span class="badge badge-info" id='info_<%= info.name %>_total'>0</span>
<span class="badge badge-success" id='info_<%= info.name %>_success'>0</span>
<span class="badge badge-important" id='info_<%= info.name %>_error'>0</span>
<div class="alert alert-info">
<span class="badge badge-inverse">Group: <%= name %></span>
<span class="badge badge-success">Normal: <%= info.success_count %></span>
<span class="badge badge-important">Fail: <%= info.error_count %></span>
<div>
<%
var nodes = info.nodes;
for (var nidx in nodes) {
var node = nodes[nidx];
if (node.status == "ok") {
%>
<span class="label label-success"><%= node.name %></span>
<% } else { %>
<span class="label label-important"><%= node.name %></span>
<% } %>
<% } %>
</div>
<div class="progress progress-striped">
<div id='bar_<%= info.name %>_success' class="bar bar-success" style="width: 100%;"></div>
<div id='bar_<%= info.name %>_danger' class="bar bar-danger" style="width: 0%;"></div>
</div>

0 comments on commit a814d68

Please sign in to comment.