Created
October 1, 2012 09:23
-
-
Save commuterjoy/3810521 to your computer and use it in GitHub Desktop.
tsung-fullstats parser
This file contains hidden or 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
# A script to extract data from tsung-fullstats.log files | |
def parse(log, key) | |
File.read(log).split('{').map { |entry| | |
next unless (entry =~ /#{key}/) | |
entry.scan(/\[.+\]/m).map { |group| | |
group.split(',').map { |timestamp| | |
timestamp.scan(/[\d\.]/).join('') | |
} | |
} | |
}.compact!.flatten! | |
end | |
def usage | |
puts " | |
Usage: #{__FILE__} <path/to/tsung-fullstats.log> <stat> | |
<stat> | |
request: Response time for each request. | |
connect: Duration of the connection establishment. | |
page: Response time for each set of requests. | |
" | |
exit 1 | |
end | |
def app | |
opts = { :log => ARGV.first, :key => ARGV[1]} | |
usage unless (opts[:log] && opts[:key] && (opts[:key] =~ /^(page|connect|request)$/)) | |
key = "(sample,%s)" % [opts[:key]] | |
parse(opts[:log], opts[:key]).join("\n") | |
end | |
puts app |
This fails for "transactions" because the sample value is not a list
WORKS:
{sample,connect,
[0.593017578125,0.47900390625,0.509033203125,0.512939453125,
0.427978515625,0.509033203125,0.573974609375,0.62890625,0.505859375,
60.676025390625]}
FAILS:
{sample,tr_foo,2.0390625}
FIX BELOW:
#!/usr/bin/env ruby
# A script to extract data from tsung-fullstats.log files
# Found here originally: https://gist.github.com/commuterjoy/3810521
=begin
**** entry=sample,tr_setup,93.367919921875},
**** result=["", "", "93.367919921875", ""]
entry=sample,page,
[38.02197265625,112.846923828125,40.094970703125,104.084228515625,
39.721923828125,96.460205078125]}
result=[["38.02197265625", "112.846923828125", "40.094970703125", "104.084228515625", "39.721923828125", "96.460205078125"]]
=end
def parse_entry_containing_key (entry)
result=nil;
scan = entry.scan(/\[.+\]/m).map { |group|
group.split(',').map { |timestamp|
timestamp.scan(/[\d\.]/).join('')
}
};
if (scan.size()>0)
# e.g., entry=sample,page,
# [38.02197265625,112.846923828125,40.094970703125,104.084228515625,
#39.721923828125,96.460205078125]}
result= scan;
else
#e.g., entry=sample,transaction,93.367919921875}
result= entry.split(',').map { |timestamp|
timestamp.scan(/[\d\.]/).join('')
}
result.reject! { |s| s.empty? }
end
return result
end
def parse(log, key)
File.read(log).split('{').map { |entry|
next unless (entry =~ /#{key}/)
parse_entry_containing_key(entry)
}.compact!.flatten!
end
def usage
puts "
Usage: #{__FILE__} <path/to/tsung-fullstats.log> <stat>
<stat>
request: Response time for each request.
connect: Duration of the connection establishment.
page: Response time for each set of requests.
"
exit 1
end
def app
opts = { :log => ARGV.first, :key => ARGV[1]}
usage unless (opts[:log] && opts[:key] ) #&& (opts[:key] =~ /^(page|connect|request)$/))
key = "(sample,%s)" % [opts[:key]]
parse(opts[:log], opts[:key]).join("\n")
end
puts app
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like so,