Permalink
Browse files

Better graphs + load average :)

  • Loading branch information...
1 parent 2e3d3f8 commit c10f32a9916660dc4c878c9e9f6fe881e8aa2943 @3rd-Eden committed Apr 11, 2011
Showing with 77 additions and 44 deletions.
  1. +3 −1 examples/default.js
  2. +13 −13 lib/cluster.exception.js
  3. +28 −21 lib/format.js
  4. +31 −7 lib/history.js
  5. +2 −2 tests/cluster.exception.test.js
View
@@ -9,6 +9,8 @@ var app = http.createServer(function httpServer(req, res){
console.info('Im a console.info');
console.warn('Im a console.warn');
console.log('Im a console.log');
+ console.error('Im a console.error');
+ console.info(req);
throw new Error("Omfg, uncaught error");
}
@@ -22,4 +24,4 @@ cluster = cluster(app)
.use(exception({to: 'info+cluster.exception@3rd-Eden.com'}))
.listen(8080);
-console.log('Staring application');
+console.log('Starting application');
@@ -48,10 +48,10 @@ exports = module.exports = function exception(options){
* Provides a JSON view of the current environment details such
* as load, memory usage, versioning information and so on.
*
- * @param {Error} exception The unchaught exception
+ * @param {Error} exception The unchaught exception.
* @param {Cluster} instance A reference to the cluster object.
*
- * @returns {Object} details about the exception
+ * @returns {Object} details about the exception.
* @api private
*/
function exception(error, instance){
@@ -60,7 +60,7 @@ exports = module.exports = function exception(options){
// Details about the current environment of the Node process
// this can be helpfull if you have multiple `cluster` instances
- // running and reporting to the same account
+ // running and reporting to the same account.
environment: {
root: process.cwd()
, arguments: process.argv
@@ -76,21 +76,21 @@ exports = module.exports = function exception(options){
}
}
- // Some basic details about the current OS we are running on
+ // Some basic details about the current OS we are running on.
, os: {
platform: process.platform
, type: os.type()
, release: os.release()
, hostname: os.hostname()
}
- // The actual error that occured
+ // The actual error that occured.
, exception: {
message: error.message
, stack: error.stack
}
- // Details about the cluster instance
+ // Details about the cluster instance.
, cluster: {
child: instance.isChild
, worker: instance.isWorker
@@ -102,7 +102,7 @@ exports = module.exports = function exception(options){
, env: instance.env
}
- // When did the exception occure
+ // When did the exception occure.
, date: timestamp()
};
@@ -115,7 +115,7 @@ exports = module.exports = function exception(options){
});
}
- // add the graphs
+ // add the graphs.
if (history && history.keys.length){
details.graph = {};
history.keys.forEach(function addGraphs(key){
@@ -132,7 +132,7 @@ exports = module.exports = function exception(options){
/**
* Simple string based replaces / template system.
*
- * @param {String} string The template
+ * @param {String} string The template.
* @param {Object} data The data that is used to replace variables from the string.
*
* @returns {String} result
@@ -166,7 +166,7 @@ exports = module.exports = function exception(options){
});
/**
- * Pre-compile the template
+ * Pre-compile the email template.
*/
template = jade.compile(
fs.readFileSync(
@@ -179,9 +179,9 @@ exports = module.exports = function exception(options){
);
/**
- * The actual plugin
+ * The actual plugin.
*
- * @param {Cluster} cluster A worker or client instance
+ * @param {Cluster} instance A worker or client instance.
* @api public
*/
function plugin(instance){
@@ -238,4 +238,4 @@ exports = module.exports = function exception(options){
/**
* Library version.
*/
-exports.version = "0.0.0";
+exports.version = "0.0.1";
View
@@ -1,25 +1,32 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
+/**
+ * @license
+ * Copyright Joyent, Inc. and other Node contributors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to permit
+ * persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * code copy / inspiration from https://github.com/joyent/node/blob/master/lib/console.js
+ */
-// code copy / inspiration from https://github.com/joyent/node/blob/master/lib/console.js
+/**
+ * Module dependencies
+ */
var util = require('util')
, formatRegExp = /%[sdj]/g;
View
@@ -99,24 +99,24 @@ History.prototype.toGraph = function toGraph(key){
tmp.high = tmp.sorted[0];
tmp.low = tmp.sorted[ tmp.sorted.length - 1 ];
- result['mem_' + type] = base + 't:' + points.join(',') + '&chtt=memoryUsage+'+ type + ' (MB)' +
+ result['mem_' + type] = base + 't:' + points.join(',') + '&chtt=Process+memory+usage+'+ type + '+(MB)' +
'&chds=' +tmp.low + ',' + tmp.high +
- '&chxr=0,' +tmp.low + ',' + tmp.high +'&chxt=r&chxl=0:|mb';
+ '&chxr=0,' +tmp.low + ',' + tmp.high +'&chxt=r';
}
});
break;
case 'freemem':
if (i){
- while(i--) points.push(History.bytesToMb(data[i]));
+ while(i--) points.push(this.totalmem - History.bytesToMb(data[i]));
tmp.sorted = points.sort(function sortTimes(a,b){return b - a });
tmp.high = tmp.sorted[0];
tmp.low = tmp.sorted[ tmp.sorted.length - 1 ];
- result['mem_' + key] = base + 't:' + points.join(',') + '&chtt=Server+'+ key + ' (MB)' +
- '&chds=' +tmp.low + ',' + tmp.high +
- '&chxr=0,' +tmp.low + ',' + tmp.high +'&chxt=r&chxl=0:|mb';
+ result['mem_' + key] = base + 't:' + points.join(',') + '&chtt=Total+memory+(limit+'+ this.totalmem+'+MB)' +
+ '&chds=' +tmp.low + ',' + this.totalmem +
+ '&chxr=0,' +tmp.low + ',' + this.totalmem +'&chxt=r';
}
break;
@@ -164,7 +164,31 @@ History.prototype.toGraph = function toGraph(key){
});
break;
- case 'loadavg':
+ case 'loadaverage':
+ if (i){
+ tmp.labels = {
+ '0': 'Server load 1 minute interval'
+ , '1': 'Server load 5 minute interval'
+ , '2': 'Server load 15 minute interval'
+ }
+
+ Object.keys(tmp.labels).forEach(function(key){
+ points = [];
+ i = data.length;
+
+ while(i--){
+ points.push(data[i][key]);
+ }
+
+ tmp.sorted = points.sort(function sortTimes(a,b){return b - a });
+ tmp.high = tmp.sorted[0];
+ tmp.low = tmp.sorted[ tmp.sorted.length - 1 ];
+
+ result['load_' + key] = base + 't:' + points.join(',') + '&chtt='+ tmp.labels[key] +
+ '&chds=' +tmp.low + ',' + tmp.high +
+ '&chxr=0,' +tmp.low + ',' + tmp.high +'&chxt=r';
+ })
+ }
break;
}
@@ -46,11 +46,11 @@ module.exports = {
Object.keys(result).forEach(function(key){
if (result[key]) result[key].should.have.string('google');
- })
+ });
});
history.destroy();
- }, (history.duration * 12) + 100)
+ }, (history.duration * 12) + 100);
},
'exception constructor': function(){

0 comments on commit c10f32a

Please sign in to comment.