Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ try {
process.exit(1);
}

console.log('Playing ' + config.source + ' against ' + config.target.host + ':' + config.target.port);

// Require the necessary modules
var http = config.target.port == '443' ? require('https') : require('http');
var Lazy = require('lazy');
var spawn = require('child_process').spawn;
var logfile = spawn('cat', [config.source]);

// Set up some variables
var regexLogLine = /^[0-9a-f.:]+ - - \[([0-9]{2}\/[a-z]{3}\/[0-9]{4}):([0-9]{2}:[0-9]{2}:[0-9]{2}[^\]]*)\] \"([^\"]+)\" [0-9]+ [0-9]+/i;
var regexLogLine = /^[0-9a-f.:]+ - ([^ ]+) \[([0-9]{2}\/[a-z]{3}\/[0-9]{4}):([0-9]{2}:[0-9]{2}:[0-9]{2}[^\]]*)\] \"([^\"]+)\" [0-9]+ [0-9]+/i;
var regexHttpRequest = /^(GET|POST) (.+) HTTP\/(1.[0-1])$/i;
var dtStart = Date.now();
var dtDuration = 0;
Expand All @@ -46,21 +48,22 @@ Lazy(logfile.stdout)
// Chop the line
var parts = regexLogLine.exec(line);
if ( parts != null ) {
var recDate = Date.parse(new Date(parts[1]+' '+parts[2]));
var recDate = Date.parse(new Date(parts[2]+' '+parts[3]));

// Determine the earliest datetime covered by log
if (recDate < dtStart ) {
dtStart = recDate;
}

// Process the HTTP request portion
var httpRec = regexHttpRequest.exec(parts[3]);
var httpRec = regexHttpRequest.exec(parts[4]);
if ( httpRec != null ) {
return {
datetime: recDate,
method: httpRec[1],
http: httpRec[3],
uri: httpRec[2]
uri: httpRec[2],
username: parts[1] != '-' ? parts[1] : (!config.anonymousUser ? null : config.anonymousUser)
};
}
}
Expand Down Expand Up @@ -109,20 +112,30 @@ Lazy(logfile.stdout)
// FIRE ZE MISSILES!!...er, requests, I mean
requestSet[runOffset].forEach(function(item){
var reqNum = reqSeq++;
var toString = reqNum + ': ' + (item.username == null ? '' : (item.username + '@')) + item.uri;
console.log(toString);
var req = http.request({
host: config.target.host,
port: config.target.port,
path: item.uri,
method: item.method,
reqStart: new Date().getTime(),
agent: false
agent: false,
auth: item.username == null ? null : (item.username + ':')
},
function(resp) {}
)
.on('socket', function() { timings[reqNum] = new Date().getTime(); })
.on('error', function(e) {
console.log(toString + ': ' + e.message);
if(e.message.indexOf('getaddrinfo ENOTFOUND') > -1 || e.message.indexOf('connect EMFILE') > -1) {
console.log('Exiting');
process.exit(1);
}
})
.on('response', function(resp) {
var diff = (new Date().getTime()) - timings[reqNum];
console.log(' - #' + reqNum + ' [DT=' + diff + 'ms, R=' + resp.statusCode + ']'); }
console.log(toString + ' [DT=' + diff + 'ms, R=' + resp.statusCode + ']'); }
);
req.end();
});
Expand Down