Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 178.47.189.163 - - [12/Dec/2015:18:53:11 +0100] "POST /administrator/index.php HTTP/1.1" 200 4494 "http://almhuette-raith.at/administrator/" "Mozilla/5.0 (Windows NT 6.0; rv:34.0) Gecko/20100101 Firefox/34.0" "-"
- # http://www.almhuette-raith.at/apache-log/access.log
- rx = /^
- (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+ # ip-address
- .+?\s+
- .+?\s+
- \[(\d{1,2})\/(\w+)\/(\d+):(\d+):(\d+):(\d+)\s\+(\d+)\]\s+ # datetime
- \"(\w+) (.+?) ([\w\/\.]+)\"\s+ # method resource protocol
- (\d+)\s+ # status
- .+?\s+
- \"(.*?)\"\s+ # host
- \"(.*?)\"\s+ # user-agent
- \".+?\"
- $/x
- requests_count = 0
- error_4xx_count = 0
- error_5xx_count = 0
- resources = Hash.new
- ips = Hash.new
- File.open("access.log").each do |line|
- # p line.match(rx)
- requests_count += 1
- res = Hash.new
- res["ip"],
- res["day"],
- res["month"],
- res["year"],
- res["hour"],
- res["minute"],
- res["second"],
- res["zone"],
- res["method"],
- res["resource"],
- res["protocol"],
- res["status"],
- res["host"],
- res["user-agent"] = line.match(rx).captures
- if res["status"].start_with? "4"
- error_4xx_count += 1
- elsif res["status"].start_with? "5"
- error_5xx_count += 1
- end
- if resources[res["resource"]].nil?
- resources[res["resource"]] = 1
- else
- resources[res["resource"]] += 1
- end
- if ips[res["ip"]].nil?
- ips[res["ip"]] = 1
- else
- ips[res["ip"]] += 1
- end
- end
- puts "Проанализировано #{requests_count} записей"
- puts "Количество 4хх-ошибок #{error_4xx_count} (#{error_4xx_count.to_f / requests_count * 100}%)"
- puts "Количество 5хх-ошибок #{error_5xx_count} (#{error_5xx_count.to_f / requests_count * 100}%)"
- puts resources
- puts ips
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement