Skip to content
Browse files

Change log file names to use toISOString() rather than millis

  • Loading branch information...
1 parent d4893f8 commit d0a7b4e134031dbf51c27f84cdb86e3e6f7cdc03 @jonjlee jonjlee committed Jul 29, 2011
Showing with 5 additions and 4 deletions.
  1. +1 −0 RELEASE-NOTES.md
  2. +1 −1 lib/monitoring/statslogger.js
  3. +1 −1 lib/reporting/report.js
  4. +2 −2 nodeload.js
View
1 RELEASE-NOTES.md
@@ -5,6 +5,7 @@ Compatible with node v0.4.x
Features:
* Add graphJmx() and graphProcess(); deprecate spawnAndMonitor(). These provide an easy way to graph JMX attributes as well as output from external processes, such as iostat.
+* More readable date strings are used in log files names
* rps is a separate stat from result codes
* Test Results page timestamp does not auto-update on open
* X-axes now use real timestamps rather than minutes since test start
View
2 lib/monitoring/statslogger.js
@@ -9,7 +9,7 @@ var LogFile = require('../stats').LogFile;
/** StatsLogger writes interval stats from a Monitor or MonitorGroup to disk each time it emits 'update' */
var StatsLogger = exports.StatsLogger = function StatsLogger(monitor, logNameOrObject) {
- this.logNameOrObject = logNameOrObject || ('results-' + START.getTime() + '-stats.log');
+ this.logNameOrObject = logNameOrObject || ('results-' + START.toISOString() + '-stats.log');
this.monitor = monitor;
this.logger_ = this.log_.bind(this);
};
View
2 lib/reporting/report.js
@@ -126,7 +126,7 @@ Chart.prototype = {
var ReportGroup = exports.ReportGroup = function() {
this.reports = [];
- this.logNameOrObject = 'results-' + START.getTime() + '.html';
+ this.logNameOrObject = 'results-' + START.toISOString() + '.html';
};
ReportGroup.prototype = {
addReport: function(report) {
View
4 nodeload.js
@@ -75,7 +75,7 @@ if(val!==undefined){self.stats.put(val);}};};StatsCollectors['concurrency']=func
if(http.req.body){self.stats.put(http.req.body.length);}}};};StatsCollectors['response-bytes']=function ResponseBytesCollector(){var self=this;self.stats=new Accumulator();self.end=function(context,http){if(http&&http.res){http.res.on('data',function(chunk){self.stats.put(chunk.length);});}};};StatsCollectors['uniques']=function UniquesCollector(){var self=this;self.stats=new Uniques();self.end=function(context,http){if(http&&http.req){self.stats.put(http.req.path);}};};StatsCollectors['uniques'].disableIntervalCollection=true;StatsCollectors['http-errors']=function HttpErrorsCollector(params){var self=this;self.stats=new Accumulator();self.successCodes=params.successCodes||[200];self.logfile=(typeof params.log==='string')?new LogFile(params.log):params.log;self.logResBody=(params.hasOwnProperty('logResBody'))?params.logResBody:true;self.end=function(context,http){if(self.successCodes.indexOf(http.res.statusCode)<0){self.stats.put(1);if(self.logfile){util.readStream(http.res,function(body){var logObj={ts:new Date(),req:{headers:http.req._header,body:http.req.body,},res:{statusCode:http.res.statusCode,headers:http.res.headers}};if(self.logResBody){logObj.res.body=body;}
self.logfile.put(JSON.stringify(logObj)+'\n');});}}};};StatsCollectors['http-errors'].disableIntervalCollection=true;StatsCollectors['slow-responses']=function HttpErrorsCollector(params){var self=this;self.stats=new Accumulator();self.threshold=params.threshold||1000;self.logfile=(typeof params.log==='string')?new LogFile(params.log):params.log;self.logResBody=(params.hasOwnProperty('logResBody'))?params.logResBody:true;self.start=function(context){context.start=new Date();};self.end=function(context,http){var runTime=new Date()-context.start;if(runTime>self.threshold){self.stats.put(1);if(self.logfile){util.readStream(http.res,function(body){var logObj={ts:new Date(),req:{headers:http.req._header,body:http.req.body,},res:{statusCode:http.res.statusCode,headers:http.res.headers},latency:runTime};if(self.logResBody){logObj.res.body=body;}
self.logfile.put(JSON.stringify(logObj)+'\n');});}}};};StatsCollectors['slow-responses'].disableIntervalCollection=true;var BUILD_AS_SINGLE_FILE;if(!BUILD_AS_SINGLE_FILE){var START=require('../config').NODELOAD_CONFIG.START;var LogFile=require('../stats').LogFile;}
-var StatsLogger=exports.StatsLogger=function StatsLogger(monitor,logNameOrObject){this.logNameOrObject=logNameOrObject||('results-'+START.getTime()+'-stats.log');this.monitor=monitor;this.logger_=this.log_.bind(this);};StatsLogger.prototype.start=function(){this.createdLog=(typeof this.logNameOrObject==='string');this.log=this.createdLog?new LogFile(this.logNameOrObject):this.logNameOrObject;this.monitor.on('update',this.logger_);return this;};StatsLogger.prototype.stop=function(){if(this.createdLog){this.log.close();this.log=null;}
+var StatsLogger=exports.StatsLogger=function StatsLogger(monitor,logNameOrObject){this.logNameOrObject=logNameOrObject||('results-'+START.toISOString()+'-stats.log');this.monitor=monitor;this.logger_=this.log_.bind(this);};StatsLogger.prototype.start=function(){this.createdLog=(typeof this.logNameOrObject==='string');this.log=this.createdLog?new LogFile(this.logNameOrObject):this.logNameOrObject;this.monitor.on('update',this.logger_);return this;};StatsLogger.prototype.stop=function(){if(this.createdLog){this.log.close();this.log=null;}
this.monitor.removeListener('update',this.logger_);return this;};StatsLogger.prototype.log_=function(){var summary=this.monitor.interval.summary();this.log.put(JSON.stringify(summary)+',\n');};var BUILD_AS_SINGLE_FILE;if(!BUILD_AS_SINGLE_FILE){var util=require('../util');var StatsCollectors=require('./collectors');var StatsLogger=require('./statslogger').StatsLogger;var EventEmitter=require('events').EventEmitter;}
var Monitor=exports.Monitor=function Monitor(){EventEmitter.call(this);util.PeriodicUpdater.call(this);this.targets=[];this.setStats.apply(this,arguments);};util.inherits(Monitor,EventEmitter);Monitor.prototype.setStats=function(stats){var self=this,summarizeStats=function(){var summary={ts:new Date()};if(self.name){summary.name=self.name;}
util.forEach(this,function(statName,stats){summary[statName]=stats.summary();});return summary;};self.collectors=[];self.stats={};self.interval={};stats=(stats instanceof Array)?stats:Array.prototype.slice.call(arguments);stats.forEach(function(stat){var name=stat,params;if(typeof stat==='object'){name=stat.name;params=stat;}
@@ -102,7 +102,7 @@ if(callback){callback(data?fn(data):fn);}
else{return data?fn(data):fn;}}};exports.create=template.create.bind(template);var BUILD_AS_SINGLE_FILE;if(!BUILD_AS_SINGLE_FILE){var util=require('../util');var querystring=require('querystring');var LogFile=require('../stats').LogFile;var template=require('./template');var config=require('../config');var REPORT_SUMMARY_TEMPLATE=require('./summary.tpl.js').REPORT_SUMMARY_TEMPLATE;var NODELOAD_CONFIG=config.NODELOAD_CONFIG;var START=NODELOAD_CONFIG.START;var DYGRAPH_SOURCE=require('./dygraph.tpl.js').DYGRAPH_SOURCE;}
var Chart;var Report=exports.Report=function(name){this.name=name;this.uid=util.uid();this.summary={};this.charts={};};Report.prototype={getChart:function(name){if(!this.charts[name]){this.charts[name]=new Chart(name);}
return this.charts[name];},updateFromMonitor:function(monitor){monitor.on('update',this.doUpdateFromMonitor_.bind(this,monitor,''));return this;},updateFromMonitorGroup:function(monitorGroup){var self=this;monitorGroup.on('update',function(){util.forEach(monitorGroup.monitors,function(monitorname,monitor){self.doUpdateFromMonitor_(monitor,monitorname);});});return self;},doUpdateFromMonitor_:function(monitor,monitorname){var self=this;monitorname=monitorname?monitorname+' ':'';util.forEach(monitor.stats,function(statname,stat){util.forEach(stat.summary(),function(name,val){self.summary[self.name+' '+monitorname+statname+' '+name]=val;});if(monitor.interval[statname]){self.getChart(monitorname+statname).put(monitor.interval[statname].summary());}});}};var Chart=exports.Chart=function(name){this.name=name;this.uid=util.uid();this.columns=["time"];this.rows=[[Date.now()]];};Chart.prototype={put:function(data){var self=this,row=[Date.now()];util.forEach(data,function(column,val){var col=self.columns.indexOf(column);if(col<0){col=self.columns.length;self.columns.push(column);self.rows[0].push(0);}
-row[col]=val;});self.rows.push(row);},updateFromEventEmitter:function(eventEmitter,fields,event){var self=this;eventEmitter.on(event||'data',function(data){var row={};fields.forEach(function(i){if(data[i]!==undefined){row[i]=data[i];}});self.put(row);});}};var ReportGroup=exports.ReportGroup=function(){this.reports=[];this.logNameOrObject='results-'+START.getTime()+'.html';};ReportGroup.prototype={addReport:function(report){report=(typeof report==='string')?new Report(report):report;this.reports.push(report);return report;},getReport:function(report){var reports=this.reports.filter(function(r){return r.name===report;});return reports[0]||this.addReport(report);},setLogFile:function(logNameOrObject){this.logNameOrObject=logNameOrObject;},setLoggingEnabled:function(enabled){clearTimeout(this.loggingTimeoutId);if(enabled){this.logger=this.logger||(typeof this.logNameOrObject==='string')?new LogFile(this.logNameOrObject):this.logNameOrObject;this.loggingTimeoutId=setTimeout(this.writeToLog_.bind(this),this.refreshIntervalMs);}else if(this.logger){this.logger.close();this.logger=null;}
+row[col]=val;});self.rows.push(row);},updateFromEventEmitter:function(eventEmitter,fields,event){var self=this;eventEmitter.on(event||'data',function(data){var row={};fields.forEach(function(i){if(data[i]!==undefined){row[i]=data[i];}});self.put(row);});}};var ReportGroup=exports.ReportGroup=function(){this.reports=[];this.logNameOrObject='results-'+START.toISOString()+'.html';};ReportGroup.prototype={addReport:function(report){report=(typeof report==='string')?new Report(report):report;this.reports.push(report);return report;},getReport:function(report){var reports=this.reports.filter(function(r){return r.name===report;});return reports[0]||this.addReport(report);},setLogFile:function(logNameOrObject){this.logNameOrObject=logNameOrObject;},setLoggingEnabled:function(enabled){clearTimeout(this.loggingTimeoutId);if(enabled){this.logger=this.logger||(typeof this.logNameOrObject==='string')?new LogFile(this.logNameOrObject):this.logNameOrObject;this.loggingTimeoutId=setTimeout(this.writeToLog_.bind(this),this.refreshIntervalMs);}else if(this.logger){this.logger.close();this.logger=null;}
return this;},reset:function(){this.reports={};},getHtml:function(){var self=this,t=template.create(REPORT_SUMMARY_TEMPLATE);return t({DYGRAPH_SOURCE:DYGRAPH_SOURCE,querystring:querystring,refreshPeriodMs:self.refreshIntervalMs,reports:self.reports});},writeToLog_:function(){this.loggingTimeoutId=setTimeout(this.writeToLog_.bind(this),this.refreshIntervalMs);this.logger.clear(this.getHtml());}};var BUILD_AS_SINGLE_FILE;if(!BUILD_AS_SINGLE_FILE){var ReportGroup=require('./report').ReportGroup;var config=require('../config');var NODELOAD_CONFIG=config.NODELOAD_CONFIG;var HTTP_SERVER=require('../http').HTTP_SERVER;}
var REPORT_MANAGER=exports.REPORT_MANAGER=new ReportGroup();NODELOAD_CONFIG.on('apply',function(){REPORT_MANAGER.refreshIntervalMs=REPORT_MANAGER.refreshIntervalMs||NODELOAD_CONFIG.AJAX_REFRESH_INTERVAL_MS;REPORT_MANAGER.setLoggingEnabled(NODELOAD_CONFIG.LOGS_ENABLED);});HTTP_SERVER.addRoute('^/$',function(url,req,res){var html=REPORT_MANAGER.getHtml();res.writeHead(200,{"Content-Type":"text/html","Content-Length":html.length});res.write(html);res.end();});HTTP_SERVER.addRoute('^/reports$',function(url,req,res){var json=JSON.stringify(REPORT_MANAGER.reports);res.writeHead(200,{"Content-Type":"application/json","Content-Length":json.length});res.write(json);res.end();});var BUILD_AS_SINGLE_FILE;if(!BUILD_AS_SINGLE_FILE){var child_process=require('child_process');var REPORT_MANAGER=require('./reportmanager').REPORT_MANAGER;var util=require('../util');var path=require('path');}
var graphProcess;var graphJmx=exports.graphJmx=function(options){var m=module;var jmxstat,found=false;while(m&&!found){jmxstat=path.join(path.dirname(m.filename),'jmxstat/jmxstat.jar');found=path.existsSync(jmxstat);m=m.parent;}

0 comments on commit d0a7b4e

Please sign in to comment.
Something went wrong with that request. Please try again.