Skip to content

Instantly share code, notes, and snippets.

@gorsuch
Created November 24, 2010 03:12
Show Gist options
  • Save gorsuch/713039 to your computer and use it in GitHub Desktop.
Save gorsuch/713039 to your computer and use it in GitHub Desktop.
simple http access log filter, assuming last field is time in microseconds
#!/usr/bin/env ruby
# assumes apache log file looks like this (all we care about is the final field):
# LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %D" custom
require 'optparse'
options = {}
options[:time] = 1
OptionParser.new do |opts|
opts.banner = "Usage: whittle.rb [options] logfile"
opts.on("-t", "--time t", "Time (in seconds) to filter on") do |t|
options[:time] = t.to_i
end
end.parse!
begin
ARGF.each do |line|
time = line.split(' ').last.to_i
puts line if time > (options[:time] * 1000000)
end
rescue Interrupt
# just die if someone hits ctrl-c
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment