Created
August 1, 2014 04:20
-
-
Save radamanthus/12f88d39abc870b83b21 to your computer and use it in GitHub Desktop.
Hourly request counts on an Nginx log file
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
# Usage: ruby nginx-requests.rb logfilename 31 Jul 2014 | |
logfilename = ARGV[0] | |
day = ARGV[1] | |
month = ARGV[2] | |
year = ARGV[3] | |
hours = (0..24).to_a | |
hours.each do |hour| | |
hour_str = sprintf("%02d", hour) | |
cmd = %{grep "#{day}/#{month}/#{year}:#{hour_str}:" #{logfilename} | wc -l} | |
puts cmd | |
result = `#{cmd}` | |
puts result | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output here is different, and this isn't filtering for the day (although you could add that to the grep), but it only takes one pass over the input file: