Permalink
Browse files

Work on the jade view + small bug fixes for the graphs generation

  • Loading branch information...
3rd-Eden committed Apr 10, 2011
1 parent 51fae16 commit 6daea4edc30ba3cf927466d306ed8d3bb1a546a5
Showing with 123 additions and 27 deletions.
  1. +4 −0 .gitignore
  2. +1 −1 examples/basic.js
  3. +22 −0 examples/default.js
  4. +1 −0 examples/logs/.gitignore
  5. +1 −2 examples/multiple-email.js
  6. +1 −0 examples/pids/.gitignore
  7. +17 −13 lib/cluster.exception.js
  8. +13 −7 lib/history.js
  9. +63 −4 views/basic.jade
View
@@ -0,0 +1,4 @@
+.DS_Store
+node_modules
+prototypes
+*.sock
View
@@ -13,5 +13,5 @@ cluster(app)
.use(cluster.pidfiles('pids'))
.use(cluster.cli())
.use(cluster.repl(8888))
- .use(exception({to: 'info@3rd-Eden.com'}))
+ .use(exception({to: 'info+cluster.exception@3rd-Eden.com'}))
.listen(8080)
View
@@ -0,0 +1,22 @@
+var http = require('http')
+ , cluster = require('cluster')
+ , exception = require('../');
+
+var app = http.createServer(function httpServer(req, res){
+ res.writeHead(200);
+ res.end("hello world");
+});
+
+setTimeout(function fakeError(){
+ console.log("error?");
+ throw new Error("Omfg, uncaught error");
+ cluster.destroy();
+}, 1000);
+
+cluster = cluster(app)
+ .use(cluster.stats())
+ .use(cluster.pidfiles('pids'))
+ .use(cluster.cli())
+ .use(cluster.repl(8888))
+ .use(exception({to: 'info+cluster.exception@3rd-Eden.com'}))
+ .listen(8080)
View
@@ -0,0 +1 @@
+*.log
@@ -2,7 +2,6 @@ var http = require('http')
, cluster = require('cluster')
, exception = require('../');
-
var app = http.createServer(function(req, res){
res.writeHead(200);
res.end("hello world");
@@ -14,5 +13,5 @@ cluster(app)
.use(cluster.pidfiles('pids'))
.use(cluster.cli())
.use(cluster.repl(8888))
- .use(exception({to: ['info@3rd-Eden.com', 'hello@3rd-Eden.com']}))
+ .use(exception({to: ['info+cluster.exception@3rd-Eden.com', 'hello+cluster.exception@3rd-Eden.com']}))
.listen(8080)
View
@@ -0,0 +1 @@
+*.pid
View
@@ -99,14 +99,15 @@ exports = module.exports = function exception(options){
// if we have log interception enabled, we are going
// to add these to the details aswel.
- if (method.length){
+ if (methods.length){
+ details.log = {};
methods.forEach(function addLogs(type){
details.log[type] = log[type].join('\n');
});
}
// add the graphs
- if (history.keys.length){
+ if (history && history.keys.length){
details.graph = {};
history.keys.forEach(function addGraphs(key){
var graphs = history.toGraph(key)
@@ -118,7 +119,7 @@ exports = module.exports = function exception(options){
return details;
};
-
+
/**
* Simple string based replaces / template system.
*
@@ -154,7 +155,7 @@ exports = module.exports = function exception(options){
original.apply(console, arguments);
};
});
-
+
/**
* Pre-compile the template
*/
@@ -175,45 +176,48 @@ exports = module.exports = function exception(options){
* @api public
*/
function plugin(instance){
+
// Start tracking the process history
history = new History(options.history || false);
// Add a listener to the process
- process.on("uncaughtException", function captureException(error){
+ process.on("uncaughtException", function captureException(error){
var details = exception(error, instance)
, message = {
- subject: replace(options.subject, details)
- , from: options.from
- , to: options.to
+ subject: replace(subject, details)
+ , from: from
+ , to: to
, bodyType: 'html'
, body: template(details)
};
-
+
+ console.dir(details);
+
// send the e-mail
var sendmail = new Email(message);
sendmail.send(function(err){
if (err){
console.error(err.message);
- console.log(timesamp() + 'Failed to send cluster.exception mail, outputting details to stdout:');
+ console.log(timestamp() + 'Failed to send cluster.exception mail, outputting details to stdout:');
console.dir(details);
} else {
- console.log(timesamp() + ' Great success! Cluster.exception mail send.');
+ console.log(timestamp() + ' Great success! Cluster.exception mail send.');
}
});
// mimic the default uncaught exception handling for workers
// see https://github.com/LearnBoost/cluster/blob/master/lib/worker.js#L95
if (instance.isWorker()){
// stderr for logs
- console.error( error.stack || error.message);
+ console.error(error.stack || error.message);
// report exception
instance.master.call('workerException', error)
// exit
process.nextTick(function(){
instance.destroy();
- })
+ });
}
});
};
View
@@ -22,7 +22,6 @@ var os = require('os');
*
* @api private
*/
-
var History = module.exports = function History(options){
var self = this;
@@ -81,7 +80,7 @@ History.prototype.update = function update(){
*/
History.prototype.toGraph = function toGraph(key){
var url = 'https://chart.googleapis.com/chart?cht=ls&chs=400x150&chts=222222,14'
- , base = url + '&chco=3B88D8chd='
+ , base = url + '&chco=3B88D8&chd='
, data = this.data[key]
, i = data.length
, points = []
@@ -92,18 +91,25 @@ History.prototype.toGraph = function toGraph(key){
case 'memory':
['rss', 'vsize', 'heapUsed', 'heapTotal'].forEach(function generateProcessMemoryResult(type){
points.length = 0;
- i = data.length
- while(i--) points.push(History.bytesToMb(data[i][type]));
- result[type] = base + 't:' + points.join(',') + '&chtt=memoryUsage+'+ type;
+ i = data.length;
+ if (i){
+ while(i--) points.push(History.bytesToMb(data[i][type]));
+ result[type] = base + 't:' + points.join(',') + '&chtt=memoryUsage+'+ type;
+ }
});
break;
case 'freemem': case 'totalmem':
- while(i--) points.push(History.bytesToMb(data[i]));
- result[key] = base + 't:' + points.join(',') + '&chtt=Server+'+ key;
+ if (i){
+ while(i--) points.push(History.bytesToMb(data[i]));
+ result[key] = base + 't:' + points.join(',') + '&chtt=Server+'+ key;
+ }
break;
case 'cpus':
+ // no data, return.. nothing
+ if(!data[0] || !i) return result;
+
data[0].forEach(function getCPUNames(cpu, index){
var name = 'CPU ' + ( index + 1) + ' ' + cpu.model, time;
tmp[name] = {};
View
@@ -1,5 +1,64 @@
html
- body(style="background:#fafafa; border-top:2px solid #3B88D8; font: 14px/1.4 'helvetica neue', helvetica, arial, sans-serif;")
- div(style="margin-top:25px")
- h1(style="font-size:28px") Cluster exception
- p ping
+ body(style="background:#fff; font: 14px/1.4 'helvetica neue', helvetica, arial, sans-serif; margin:0; padding:100px; color:#222")
+ h1(style="font-size:28px; margin-top:25px") Cluster exception
+ p An exception occurred on #{date} “
+ span(style="color:#3B88D8") #{exception.message}
+ |”
+ pre(style="border:1px solid #eee;padding:10px;min-width:800px;overflow:auto")#{exception.stack}
+
+ h2(style="font-size:16px; margin-top:20px") Log snapshot
+ - Object.keys(log).forEach(function(key){
+ - if(key && log[key].length){
+ h2(style="font-size:14px;color:#3B88D8")= key
+ pre(style="border:1px solid #eee;padding:10px;min-width:800px;overflow:auto")= log[key]
+ - }
+ - })
+
+ h2(style="font-size:16px; margin-top:20px") Memory history
+ img(src: graph.freemem, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.totalmem, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.rss, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.vsize, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.heapUsed, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.heapTotal, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+
+ - if(Object.keys(graph).some(function(v){return v.indexOf('load') >= 0 })){
+ h2(style="font-size:16px; margin-top:20px") Load average history
+ img(src: graph.freemem, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.totalmem, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.rss, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.vsize, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.heapUsed, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.heapTotal, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ -}
+
+ - if(Object.keys(graph).some(function(v){return v.indexOf('cpu') >= 0 })){
+ h2(style="font-size:16px; margin-top:20px") CPU Cycle history
+ img(src: graph.freemem, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.totalmem, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.rss, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.vsize, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.heapUsed, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ img(src: graph.heapTotal, style="margin:0 40px 40px 0; border:1px solid #fafafa")
+ -}
+
+ h2(style="font-size:16px; margin-top:20px") Operating System
+ - Object.keys(os).forEach(function(key){
+ dl
+ dt(style="color:#3B88D8;display:inline-block;width:200px")= key
+ dd(style="display:inline")= os[key]
+ - })
+
+ h2(style="font-size:16px; margin-top:20px") Library versioning
+ - Object.keys(environment.versions).forEach(function(key){
+ dl
+ dt(style="color:#3B88D8;display:inline-block;width:200px")= key
+ dd(style="display:inline")= environment.versions[key]
+ - })
+
+ h2(style="font-size:16px; margin-top:20px") Environment variables
+ - Object.keys(environment.env).forEach(function(key){
+ dl
+ dt(style="color:#3B88D8;display:inline-block;width:200px")= key
+ dd(style="display:inline")= environment.env[key]
+ - })

0 comments on commit 6daea4e

Please sign in to comment.