Skip to content

Commit

Permalink
add cluster monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
charsyam committed Jan 9, 2013
1 parent 419e28a commit 6d9373a
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 83 deletions.
17 changes: 13 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
"interval": 1000,
"clusters": [
{ "name": "redis-1",
"plugin": "redis",
{
"name": "redis-1",
"type": "redis",
"nodes": [
{ "name": "server1", "ip": "127.0.0.1", "port": 3001 },
{ "name": "server2", "ip": "127.0.0.1", "port": 3002 }
{ "name": "server1", "host": "127.0.0.1", "port": 3001 },
{ "name": "server2", "host": "127.0.0.1", "port": 3002 }
]
},
{
"name": "redis-2",
"type": "redis",
"nodes": [
{ "name": "server3", "host": "127.0.0.1", "port": 3001 },
{ "name": "server4", "host": "127.0.0.1", "port": 3002 }
]
}
]
Expand Down
10 changes: 9 additions & 1 deletion public/stylesheets/stat.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

.dependencies div.monitor {
width: 245px; /* we want a fixed width instead of percentage as I want the boxes to be a set size and then fill in as many as can fit in each row ... this allows 3 columns on an iPad */
height: 150px;
height: 165px;
}

.dependencies .success {
Expand Down Expand Up @@ -152,11 +152,19 @@
color: grey;
}

.dependencies .clusterTotalCommand {
color: blue;
}

.dependencies div.cell .errorPercentage {
padding-left:5px;
font-size: 12pt !important;
}

.dependencies div.cell .clusterTotalCommand{
padding-left:5px;
font-size: 12pt !important;
}

.dependencies div.monitor div.chart {
}
Expand Down
66 changes: 45 additions & 21 deletions redisstat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand All @@ -9,7 +8,8 @@ var express = require('express')
, redis = require('redis')
, config = require('./config.json')
, path = require('path')
, Storage = require('./storage');
, Storage = require('./storage')
, monitorFactory = require('./monitor/factory');

var app = express();

Expand Down Expand Up @@ -39,35 +39,54 @@ http.createServer(app).listen(app.get('port'), function(){
var storage = new Storage();
require('./routes/getdata').add_routes(app, storage);

var redislist = new Array();
var self = this;
self.request_count = 0;
self.check = false;

self.clusters = new Array();
self.max_request_count = 0;

for (var i in config.clusters) {
var cluster= config.clusters[i];
if (cluster.plugin == "redis") {
for(var idx in cluster.nodes) {
var node = cluster.nodes[idx];
redislist[idx] = redis.createClient(node.port, node.ip);
redislist[idx]['name'] = node.name;
redislist[idx].on("error", function(err) {
console.error("Error connecting to redis", err);
});
}
require('./routes/index').add_routes(app, redislist);
var cluster = config.clusters[i];
var nodes = new Array();
var register = false;
for(var idx in cluster.nodes) {
var node = cluster.nodes[idx];
nodes[idx] = monitorFactory.create(cluster.name, cluster.type, node.host, node.port);
nodes[idx]['name'] = node.name;
self.max_request_count++;
register = true;
}

if (register == true) {
var cluster_info = {
'name': cluster.name,
'type': cluster.type,
'nodes': nodes
};
self.clusters.push(cluster_info);
}
}

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

function report() {
self.request_count--;
}

self.infos = new Object();
setInterval(function() {
if (self.check == false) {
self.check = true;
self.request_count = redislist.length;
console.log(self.request_count);
self.infos = new Array();
for (var i in redislist) {
var client = redislist[i];
info(client);
self.request_count = self.max_request_count;
self.infos['nodes'] = new Array();
for (var i in self.clusters) {
var cluster = self.clusters[i];
self.infos[cluster.name] = 0;
for (var idx in cluster.nodes) {
var node = cluster.nodes[idx];
info(node);
}
}
}
},2000);
Expand Down Expand Up @@ -101,7 +120,12 @@ function info(client) {
o["port"] = client.port;
o["host"] = client.host;
o["name"] = client.name;
self.infos.push(o);
o["cluster_name"] = client.cluster_name;
o["type"] = client.type;

self.infos[client.cluster_name] += parseInt(o.total_commands_processed);
self.infos.nodes.push(o);


self.request_count--;
if (self.request_count == 0) {
Expand Down
5 changes: 2 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* GET home page.
*/

module.exports.add_routes = function(app, servers) {
console.log(servers);
module.exports.add_routes = function(app, clusters) {
app.get('/', function(req, res) {
res.render('index', { title: 'Redis-Stat',
servers: servers });
clusters: clusters});
});
};

8 changes: 2 additions & 6 deletions storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ function Storage() {
}

Storage.prototype.report_all = function(callback) {
var self = this;
callback(null, {services: self.infos});
callback(null, { services: this.infos});
};

Storage.prototype.store = function(infos) {
var self = this;
var old_infos = self.infos;
self.infos = infos;
delete old_infos;
this.infos = infos;
};

module.exports = Storage;
Loading

0 comments on commit 6d9373a

Please sign in to comment.