Created
September 16, 2014 08:26
-
-
Save sonots/9ae0167d31d7f4b42c9a to your computer and use it in GitHub Desktop.
https://github.com/sonots/isucon3_cheatsheet/blob/master/10.nginx.md のLTSVログフォーマットを想定
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
require 'uri' | |
stats = {} | |
STDIN.readlines.each do |line| | |
uri, reqtime = line.split("\t") | |
path = uri.split('?').first | |
reqtime = reqtime.to_f | |
stat = stats[path] ||= { :count => 0, :sum => 0, :min => 0, :max => 0} | |
stat[:sum] += reqtime | |
stat[:max] = [stat[:max], reqtime].max | |
stat[:min] = [stat[:min], reqtime].min | |
stat[:count] += 1 | |
end | |
stats.each do |path, val| | |
val[:mean] = val[:sum] / val[:count].to_f | |
out = { :path => path }.merge(val) | |
puts out.map {|key, v| "#{key}:#{v}" }.join("\t") | |
end |
Author
sonots
commented
Sep 16, 2014
cat /var/log/nginx/access.log | lltsv -k uri,reqtime -K | ruby stat.rb | lltsv -k sum,count,mean,path -K | sort -n -r
355.7159999999995 1201 0.29618318068276395 /login
63.59299999999999 208 0.30573557692307685 /mypage
23.611000000000107 2195 0.010756719817767702 /
18.965 1 18.965 /report
0.0 2403 0.0 /stylesheets/isucon-bank.css
0.0 2403 0.0 /stylesheets/bootstrap.min.css
0.0 2403 0.0 /stylesheets/bootflat.min.css
0.0 2403 0.0 /images/isucon-bank.png
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment