Permalink
Browse files

Adding some more stats

Following now show in /info command
* Configuration
* Current Masters / Slaves
* Total commands, ReadOnly/Mutating,
* Number of times redis server went up/down
* Number of errors from server
  • Loading branch information...
1 parent 7eea294 commit faf34fe92329fc4cf7dbd9243a5246dcdf4a2024 @sreeix committed Sep 17, 2012
Showing with 50 additions and 33 deletions.
  1. +1 −1 lib/redis_proxy.js
  2. +5 −0 lib/server.js
  3. +10 −0 lib/stats.js
  4. +33 −31 lib/webui.js
  5. +1 −1 server.js
View
@@ -95,7 +95,7 @@ Object.defineProperty(RedisProxy.prototype, 'active', {
// balancing strategies
RedisProxy.prototype.readsToSlaves = function(command, id, callback) {
stats.incr("commands");
- stats.incr("commands:"+command);
+ // stats.incr("commands:"+command);
if(redisCommand.readOnly(command)) {
stats.incr("commands:read");
logger.debug('Read only command sending to the slave');
View
@@ -6,6 +6,7 @@ var Pool = require('connection_pool');
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var logger = require('winston');
+var stats = require('./stats');
var Server = module.exports = function(serverInfo){
@@ -99,6 +100,8 @@ Server.prototype._createConnections = function(){
Server.prototype.slave = function(server){
var self = this;
logger.info('Marking '+ this.host + ':' + this.port + ' as slave of '+ server.host+': '+ server.port);
+ stats.incr("slave:"+ this.host + ':' + this.port);
+ stats.push("slaves", this.host + ':' + this.port);
this.client.slaveof(server.client.host, server.client.port, function(err, message){
if(err){
return logger.error(err);
@@ -111,6 +114,8 @@ Server.prototype.slave = function(server){
Server.prototype._master = function (){
var self = this;
logger.info(this.options.host+":"+this.options.port+ " is slave of no one");
+ stats.incr("master:"+ this.host + ':' + this.port);
+ stats.set("master", this.host + ':' + this.port);
this.client.slaveof('no', 'one', function(err, message){
if(err){
return logger.error(err);
View
@@ -1,19 +1,29 @@
+var _ = require('underscore');
+
var data = {};
module.exports = Stats = {
incr: function(item){
if(!data[item]) data[item] = 0;
return ++data[item];
},
+
decr: function(item){
if(!data[item]) data[item] = 0;
return --data[item];
},
+
value: function(item){
return data[item] || 0;
},
+
set: function(item, value){
data[item] = value;
},
+ push : function(item, value){
+ if(!data[item]) data[item] = []
+ data[item].push(value);
+ },
+
all: function(){
return data;
}
View
@@ -1,39 +1,41 @@
-var express = require('express');
-var stats = require('./stats');
-var app = express();
+module.exports = function(config){
+ var express = require('express');
+ var stats = require('./stats');
+ var app = express();
-app.use(express.bodyParser());
-app.use(express.methodOverride());
-app.use(app.router);
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
-app.use(express.bodyParser());
-app.use(express.methodOverride());
-app.use(app.router);
-app.use(logErrors);
-app.use(clientErrorHandler);
-app.use(errorHandler);
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(logErrors);
+ app.use(clientErrorHandler);
+ app.use(errorHandler);
-function logErrors(err, req, res, next) {
- console.error(err.stack);
- next(err);
-}
-
-function clientErrorHandler(err, req, res, next) {
- if (req.xhr) {
- res.send(500, { error: 'Something blew up!' });
- } else {
+ function logErrors(err, req, res, next) {
+ console.error(err.stack);
next(err);
}
-}
-function errorHandler(err, req, res, next) {
- res.status(500);
- res.render('error', { error: err });
-}
+ function clientErrorHandler(err, req, res, next) {
+ if (req.xhr) {
+ res.send(500, { error: 'Something blew up!' });
+ } else {
+ next(err);
+ }
+ }
+
+ function errorHandler(err, req, res, next) {
+ res.status(500);
+ res.render('error', { error: err });
+ }
-app.get('/info', function(req, res){
- res.send(stats.all());
-});
+ app.get('/info', function(req, res){
+ res.send({stats: stats.all(), config: config});
+ });
-app.listen(3000);
-console.log('Listening on port 3000');
+ app.listen(3000);
+ console.log('Listening on port 3000');
+};
View
@@ -49,7 +49,7 @@ redis_proxy.watch();
if(config.show_web_ui){
logger.info("Starting the web UI.");
- require('./lib/webui');
+ require('./lib/webui')(config);
}
server.listen(listenPort, bindAddress);

0 comments on commit faf34fe

Please sign in to comment.