-require "rubygems"
-require "date"
-gem "home_run", ">= 0"
-require "apache_log_regex"
-
-NUM_LINES = 10000
-
-def uris_from_logs
- lines = []
- max_time = nil
- min_time = nil
- parser = ApacheLogRegex.new('%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %x')
- IO.popen("tail -n #{NUM_LINES} /var/log/apache2/access.log").each_line do |line|
- begin
- hash = parser.parse(line)
- uri = hash["%r"]
- t = DateTime.strptime(hash["%t"], "[%d/%b/%Y:%H:%M:%S %z]")
- min_time = [min_time, t].compact.min
- max_time = [max_time, t].compact.max
- lines << uri
- rescue ApacheLogRegex::ParseError
- # nil
- end
- end
- [min_time, max_time, lines]
-end