Created
May 17, 2016 21:10
-
-
Save cprice404/e97c260c70ff3088a73dcfdfad0bfe7a to your computer and use it in GitHub Desktop.
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 | |
request_count = 0 | |
catalog_request_count = 0 | |
environment_cat_requests = {} | |
access_logs = Dir["*access*"] | |
access_logs.each do |f| | |
File.open(f).each do |line| | |
match = line.match(/^([^\s]+) - - - ([^\s])+ ([^s]+) ("[^\"]+") (\d+) (\d+) ([^\s]+) ([^\s]+) (\d+) (\d+)$/) | |
unless match | |
raise "Line does not match regex!: '#{line}'" | |
end | |
host, timestamp, timezone, request, status, size, ip, port, duration = match.captures | |
#puts "REQUEST: #{request}" | |
request_count += 1 | |
catalog_match = request.match(/^"POST \/(\w+)\/catalog\/([\w\.\-]+) HTTP\/1\.1"$/) | |
if catalog_match | |
catalog_request_count += 1 | |
environment, certname = catalog_match.captures | |
environment_cat_requests[environment] ||= 0 | |
environment_cat_requests[environment] += 1 | |
end | |
end | |
end | |
puts "Total requests: #{request_count}" | |
puts "Catalog requests: #{catalog_request_count}" | |
puts "Environment catalog requests: #{environment_cat_requests}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an updated version that handles changes to the request logging formant in PE 2016.1: