Skip to content

Commit

Permalink
localize
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Jul 15, 2016
1 parent 0bbe40a commit 2cf1ae8
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions actions/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,53 @@ exports.status = {
'uptime':10469
},

checkRam: function(api, data, callback){
var consumedMemoryMB = Math.round(process.memoryUsage().heapUsed / 1024 / 1024 * 100) / 100;
data.response.consumedMemoryMB = consumedMemoryMB;
if(consumedMemoryMB > maxMemoryAlloted){
data.response.status = 'Unhealthy';
data.response.problems.push('Using more than 200MP of RAM/HEAP');
}

callback();
},
run: function(api, data, next){

checkEventLoop: function(api, data, callback){
api.utils.eventLoopDelay(10000, function(error, eventLoopDelay){
data.response.eventLoopDelay = eventLoopDelay;
if(eventLoopDelay > maxEventLoopDelay){
data.response.status = 'Unhealthy';
data.response.problems.push('EventLoop Blocked for more than 5ms');
/* --- Define Helpers --- */

var checkRam = function(callback){
var consumedMemoryMB = Math.round(process.memoryUsage().heapUsed / 1024 / 1024 * 100) / 100;
data.response.consumedMemoryMB = consumedMemoryMB;
if(consumedMemoryMB > maxMemoryAlloted){
data.response.status = data.connection.localize('Unhealthy');
data.response.problems.push(data.connection.localize('Using more than 200MB of RAM/HEAP'));
}

callback();
});
},
};

var checkEventLoop = function(callback){
api.utils.eventLoopDelay(10000, function(error, eventLoopDelay){
data.response.eventLoopDelay = eventLoopDelay;
if(eventLoopDelay > maxEventLoopDelay){
data.response.status = data.connection.localize('Unhealthy');
data.response.problems.push(data.connection.localize('EventLoop Blocked for more than 5ms'));
}

checkResqueQueues: function(api, data, callback){
api.tasks.details(function(error, details){
if(error){ return callback(error); }
var length = 0;
Object.keys(details.queues).forEach(function(q){
length += details.queues[q].length;
callback();
});
};

if(length > maxResqueQueueLength){
data.response.status = 'Unhealthy';
data.response.problems.push('Resque Queues filling up');
}
var checkResqueQueues = function(callback){
api.tasks.details(function(error, details){
if(error){ return callback(error); }
var length = 0;
Object.keys(details.queues).forEach(function(q){
length += details.queues[q].length;
});

callback();
});
},
if(length > maxResqueQueueLength){
data.response.status = data.connection.localize('Unhealthy');
data.response.problems.push(data.connection.localize('Resque Queues filling up'));
}

run: function(api, data, next){
data.response.status = 'Healthy';
callback();
});
};

/* --- Run --- */

data.response.status = data.connection.localize('Healthy');
data.response.problems = [];

data.response.id = api.id;
Expand All @@ -67,12 +72,11 @@ exports.status = {
data.response.description = packageJSON.description;
data.response.version = packageJSON.version;

var self = this;
self.checkRam(api, data, function(error){
checkRam(function(error){
if(error){ return next(error); }
self.checkEventLoop(api, data, function(error){
checkEventLoop(function(error){
if(error){ return next(error); }
self.checkResqueQueues(api, data, function(error){
checkResqueQueues(function(error){
next(error);
});
});
Expand Down

0 comments on commit 2cf1ae8

Please sign in to comment.