Created
November 24, 2010 03:12
-
-
Save gorsuch/713039 to your computer and use it in GitHub Desktop.
simple http access log filter, assuming last field is time in microseconds
This file contains 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
#!/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