Skip to content

Instantly share code, notes, and snippets.

@BilalBudhani
Last active December 21, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BilalBudhani/6255751 to your computer and use it in GitHub Desktop.
Save BilalBudhani/6255751 to your computer and use it in GitHub Desktop.
Ruby code to read apache logs and count the server response.
require 'rubygems'
responses = Array.new
File.foreach('logs/access.log') do |line|
log_line = line.chomp.split(/\s+/)
responses << log_line[9]
end
counts = Hash.new(0)
responses.each { |response| counts[response] += 1 }
puts counts.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment