Created
December 2, 2014 19:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request = require 'request' | |
logger = require('winston') | |
lineReader = require('line-reader') | |
q = require 'q' | |
now = new Date | |
first_time = null | |
host = 'hydra-staging.herokuapp.com' | |
port = '80' | |
totals = {} | |
fetches = [] | |
lineReader.eachLine('test4.log', (line, last)-> | |
parts = line.split(' ') | |
return unless parts.length > 5 | |
unless first_time | |
first_time = (new Date(Date.parse(parts[0]))).getTime() | |
time = (new Date(Date.parse(parts[0]))).getTime() | |
path = parts[4].replace(/^path=\"([^\"]+)\"/, '$1') | |
department = parts[5].replace(/^host=([^.]+).reviewed.com/, '$1') | |
offset = time - first_time | |
deferred = q.defer() | |
fetches.push q.delay(offset).then -> | |
start_time = (new Date).getTime() | |
request({ url: "http://#{host}:#{port}#{path}", headers: { "X-Reviewed-Category": department } }, (error, resp, body)-> | |
if error | |
logger.error("error fetching '#{path}': #{error.message}") | |
else | |
delta = (new Date).getTime() - start_time | |
logger.info("fetched #{path} with status #{resp.statusCode}, got #{body.length} bytes in #{delta}ms") | |
deferred.resolve(bytes: body.length, time: delta, status: resp.statusCode) | |
) | |
) | |
q.all(fetches).done (data)-> | |
console.log 'done!' | |
(totals[data.status] ||= {bytes: 0, time: 0})['bytes'] += data.bytes | |
totals[data.status]['time'] += data.time | |
console.log(totals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment