Skip to content

Instantly share code, notes, and snippets.

@haus
Forked from justinstoller/calc.rb
Last active February 12, 2018 18:56
Show Gist options
  • Save haus/319f2ba7333336f93698e9d1db3a6464 to your computer and use it in GitHub Desktop.
Save haus/319f2ba7333336f93698e9d1db3a6464 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'csv'
require 'zlib'
path = ARGV[0]
hours = ARGV[1]
csv = nil
options = {col_sep: "\t"}
if path.end_with?(".gz")
Zlib::GzipReader.open(path) do |gz|
csv = CSV.new(gz.read, options)
end
else
csv = CSV.open(path, options)
end
puts "Reading #{path}"
end_time = nil
intermediate = {
'node' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'filemeta plugins' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'filemeta pluginfacts' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'catalog' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'filemeta' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'report' => {'KOs' => 0, 'values' => [], 'ok' => 0}
}
csv.each do |row|
if row[0] == 'REQUEST'
type = row[4]
if row[7] != 'OK'
intermediate[type]['KOs'] += 1
else
val = row[6].to_i - row[5].to_i
if end_time.nil?
if hours
end_time = row[5].to_i + (hours.to_i * 60 * 60 * 1000)
end
else
if row[5].to_i > end_time
break
end
end
intermediate[type]['values'] << val
intermediate[type]['ok'] += 1
end
end
end
output = []
intermediate.each_pair do |type, info|
info['values'].sort!
length = info['ok']
median = (length * 0.5).to_i
p90 = (length * 0.9).to_i
p95 = (length * 0.95).to_i
p99 = (length * 0.99).to_i
output << [
type,
info['values'].first,
info['values'][median],
info['values'][p90],
info['values'][p95],
info['values'][p99],
info['values'].last,
info['ok'] + info['KOs'],
info['KOs']
]
end
puts 'endpoint,min,median,p90,p95,p99,max,count,kos'
output.each do |row|
puts row.join(",")
end
sellout:gatling justin$ time ./calc.rb logs/jruby-9.1.11.0-with-jit-and-mrpi-simulation.log > csvs/jruby-9.1.11.0-with-jit-and-mrpi-simulation.csv
real 0m6.926s
user 0m6.871s
sys 0m0.041s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment