Last active
August 29, 2015 14:02
-
-
Save gary/b3f136c38a8b1974e01a to your computer and use it in GitHub Desktop.
NGINX request time custom format
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 -w | |
require 'request_log_analyzer' | |
# for use with wvanbergen/request-log-analyzer | |
class NginxRequestTimeFormat < RequestLogAnalyzer::FileFormat::Nginx | |
line_definition :current_request_time do |line| | |
line.captures << { :name => :request_time, :type => :msec } | |
line.regexp = %r|- (\d+.\d+)$| | |
end | |
report(:append) do |analyze| | |
analyze.duration(:request_time, | |
:category => lambda { |request| request.category }, | |
:line_type => :current_request_time, | |
:title => 'Request Time', | |
) | |
end | |
end | |
if $0 == __FILE__ && ARGV.length == 0 | |
eval DATA.read, nil, $0, __LINE__+4 | |
end | |
__END__ | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
describe NginxRequestTimeFormat do | |
describe '"Request Time" access log parsing' do | |
let(:nginx_custom_format_path) { | |
File.expand_path('./nginx_request_time_format.rb', | |
File.dirname(__FILE__)) | |
} | |
subject { ::RequestLogAnalyzer::FileFormat.load(nginx_custom_format_path) } | |
describe '#parse_line' do | |
let(:sample1) { | |
'10.0.0.72 - hostname [18/Jun/2014:21:09:09 +0000] "GET /initiatives/twin-cities HTTP/1.1" 302 132 "-" "blitz.io; 84b8f00888919da514c7aa5322b3109f@69.133.50.104" - 0.066' | |
} | |
it 'should capture the request time' do | |
subject.parse_line(sample1)[:captures].must_include '0.066' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment